向窗體上添加兩個TLabel組件
首先在程序的uses段中添加對WinSock的引用
function TfrmMain
var
ComputerName: array[
Size: Cardinal;
begin
result:=
Size := MAX_COMPUTERNAME_LENGTH+
GetComputerName(ComputerName
Result:=StrPas(ComputerName);
end;
添加一個NameToIP自定義函數
function TfrmMain
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
result:=
WSAStartup(
HostEnt := GetHostByName(PChar(Name));
if HostEnt <> nil then
begin
with HostEnt^ do
result:= Format(
end;
WSACleanup;
end;
程序代碼如下
unit Unit
interface
uses
Windows
type
TfrmMain = class(TForm)
btnStart: TButton;
edtIP: TEdit;
edtName: TEdit;
Label
Label
function GetHostName:String;
procedure btnStartClick(Sender: TObject);
function NameToIP(Name:string):String;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *
function TfrmMain
var
ComputerName: array[
Size: Cardinal;
begin
result:=
Size := MAX_COMPUTERNAME_LENGTH+
GetComputerName(ComputerName
Result:=StrPas(ComputerName);
end;
procedure TfrmMain
begin
edtName
edtIP
end;
function TfrmMain
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
result:=
WSAStartup(
HostEnt := GetHostByName(PChar(Name));
if HostEnt <> nil then
begin
with HostEnt^ do
result:= Format(
Byte(h_addr^[
end;
WSACleanup;
end;
end
保存文件
單擊
From:http://tw.wingwit.com/Article/program/Delphi/201311/8404.html