unit Unitip;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls, Buttons, winsock, ExtCtrls,WinInet,IdTCPServer, IdHTTPServer;type TForm1 = class(TForm) Label1: TLabel; Button1: TButton; IdHTTP1: TIdHTTP; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function ExtractStr(Str: string): string; //格式字符串 var i,j:integer; begin Result:=''; j:=Length(str); for i:=0 to j do begin if str[i] in ['0'..'9','.'] then Result:=Result+str[i]; end; end;function IsInternet: Boolean; //检查是否连上网络 begin if InternetCheckConnection('http://www.ip138.com', 1, 0) then Result := True else Result := False; end;procedure TForm1.Button1Click(Sender: TObject); begin if IsInternet then begin Label1.Caption:='你的公网IP:'+ ExtractStr(IdHTTP1.Get('http://www.ip138.com'));//取IP地址 end else application.MessageBox('该机器未连接网络或服务器出错!','错误',mb_ok+mb_iconerror); end;procedure TForm1.FormCreate(Sender: TObject); begin Label1.Caption:=''; //初始化 end;end.我的代码如上,可是运行以后LABEL上显示出来的的是一大串数字。哪位大侠可以帮我看看是怎么回事啊?要怎么修改?先谢谢了!!急,急,急。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls, Buttons, winsock, ExtCtrls,WinInet,IdTCPServer, IdHTTPServer;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
IdHTTP1: TIdHTTP;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function ExtractStr(Str: string): string; //格式字符串
var
i,j:integer;
begin
Result:='';
j:=Length(str);
for i:=0 to j do
begin
if str[i] in ['0'..'9','.'] then
Result:=Result+str[i];
end;
end;function IsInternet: Boolean; //检查是否连上网络
begin
if InternetCheckConnection('http://www.ip138.com', 1, 0) then
Result := True
else
Result := False;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if IsInternet then
begin
Label1.Caption:='你的公网IP:'+
ExtractStr(IdHTTP1.Get('http://www.ip138.com'));//取IP地址
end
else
application.MessageBox('该机器未连接网络或服务器出错!','错误',mb_ok+mb_iconerror);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption:=''; //初始化
end;end.我的代码如上,可是运行以后LABEL上显示出来的的是一大串数字。哪位大侠可以帮我看看是怎么回事啊?要怎么修改?先谢谢了!!急,急,急。