cornermoss,很感谢你的热心帮助,你给我的代码我仔细读了,不过还有几个地方不太明白,希望你能指点指点。程序编译时,下面两个函数有错误
-------------------------------------------------------------
//得到本机地址
function TFunc.GetLocalIP:string;
begin
Result:=Powersock1.LocalIP;//本机ip,注意加个TPowersock控件 (已经加了,可参数不知道设置得对不对)
end;
---------------------------------------------------------------
//由IP得到计算机名
function GetDomainName(Ip:string):string;
var pH:PHostent; (Hostent是否应在前面再定义一下)
data:twsadata;
ii:dword;
begin
WSAStartup($101, Data);
ii:=inet_addr(pchar(ip));
pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
if (ph<>nil) then Result:=pH.h_name
else Result:='';
WSACleanup();
end;
-----------------------------------------------------------我希望你能把你给我的程序编译通过了,然后把可执行的源程序发给我,应该不会很大吧?,因为我对底层技术真的不太懂:(
-------------------------------------------------------------
//得到本机地址
function TFunc.GetLocalIP:string;
begin
Result:=Powersock1.LocalIP;//本机ip,注意加个TPowersock控件 (已经加了,可参数不知道设置得对不对)
end;
---------------------------------------------------------------
//由IP得到计算机名
function GetDomainName(Ip:string):string;
var pH:PHostent; (Hostent是否应在前面再定义一下)
data:twsadata;
ii:dword;
begin
WSAStartup($101, Data);
ii:=inet_addr(pchar(ip));
pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
if (ph<>nil) then Result:=pH.h_name
else Result:='';
WSACleanup();
end;
-----------------------------------------------------------我希望你能把你给我的程序编译通过了,然后把可执行的源程序发给我,应该不会很大吧?,因为我对底层技术真的不太懂:(
再次对不起,确实上次错了,应该还要uses WinSock
附:
***************Project1.dpr
program Project1;uses
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.******************Unit1.pas
unit Unit1;interfaceuses
Windows, Forms,Psock, WinSock, StdCtrls, Controls, Classes;type
TForm1 = class(TForm)
IP_Address_Label: TLabel;
IP_Address_Edit: TEdit;
GetDomain_Btn: TButton;
Com_Domain_Edit: TEdit;
Powersock1: TPowersock;
LocalIP_Label: TLabel;
LocalIP_Edit: TEdit;
procedure FormCreate(Sender: TObject);
procedure GetDomain_BtnClick(Sender: TObject);
private
{ Private declarations }
function GetLocalIP:String;//得到本机IP地址
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.GetLocalIP:String;
begin
Result:=Powersock1.LocalIP;
end;function GetDomainName(Ip:string):string;
var pH:PHostent; //Hostent是否应在前面再定义一下
data:twsadata;
ii:dword;
begin
WSAStartup($101, Data);
ii:=inet_addr(pchar(ip));
pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
if (ph<>nil) then Result:=pH.h_name
else Result:='';
WSACleanup();
end;procedure TForm1.FormCreate(Sender: TObject);
begin
LocalIP_Edit.Text:=GetLocalIP;
IP_Address_Edit.Text:=LocalIP_Edit.Text;
end;procedure TForm1.GetDomain_BtnClick(Sender: TObject);
begin
Com_Domain_Edit.Text:=GetDomainName(IP_Address_Edit.Text);
end;end.
****************Unit1.dfm
object Form1: TForm1
Left = 368
Top = 213
Width = 229
Height = 208
Caption = 'Form1'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object IP_Address_Label: TLabel
Left = 8
Top = 40
Width = 72
Height = 12
Caption = '输入IP地址:'
end
object LocalIP_Label: TLabel
Left = 8
Top = 144
Width = 42
Height = 12
Caption = '本机IP:'
end
object IP_Address_Edit: TEdit
Left = 88
Top = 32
Width = 121
Height = 20
TabOrder = 0
end
object GetDomain_Btn: TButton
Left = 0
Top = 64
Width = 81
Height = 25
Caption = '得到计算机名'
TabOrder = 1
OnClick = GetDomain_BtnClick
end
object Com_Domain_Edit: TEdit
Left = 88
Top = 66
Width = 121
Height = 20
TabOrder = 2
end
object LocalIP_Edit: TEdit
Left = 56
Top = 144
Width = 121
Height = 20
TabOrder = 3
end
object Powersock1: TPowersock
Port = 0
ReportLevel = 0
Left = 8
Top = 8
end
end
****************