procedure TForm1.Button1Click(Sender: TObject);
var
phost : PHostEnt;
s : pchar;
buf:string;
begin
{获得计算机名}
getmem(s,1024);
try
strpcopy(s,edit1.text);
phost := GetHostByName(s);
if phost<>nil then
begin
buf:=phost^.h_Name;
edit2.text:=copy(buf,1,pos('.',buf)-1);
end
else
edit2.text:='Failed';
finally
freemem(s);
end;
end;
var
phost : PHostEnt;
s : pchar;
buf:string;
begin
{获得计算机名}
getmem(s,1024);
try
strpcopy(s,edit1.text);
phost := GetHostByName(s);
if phost<>nil then
begin
buf:=phost^.h_Name;
edit2.text:=copy(buf,1,pos('.',buf)-1);
end
else
edit2.text:='Failed';
finally
freemem(s);
end;
end;
解决方案 »
- 如何分离listbox1中的信息,读取st.dat内的信息
- 我想担任Windows sdk的版主,希望大家支持
- 如何截获API kernel32中的DeleteFileA,DeleteFileW 达到禁止删除文件的目的
- 请问DbGirdeh是什么控件,我在每个控件页中都找不到呀?
- 哪位朋友有用delphi写的des算法的源码?可不可以提供一下.现在需要很急的.谢谢!
- 关于vfw和编码器的问题,急!!!
- 在DEPHI 程序中如何取得本机的IP?
- 关于通配符使用问题
- idglobal是那里的文件啊?
- 朋友们,提供几个下载winXP风格的控件的地方呀?
- 请问怎样将一个listbox的所选项移到另一个listbox中去?
- TStrings和TStringList的问题(一定给分)
procedure TForm1.Button1Click(Sender: Tobject);
var
ComputerName:pchar;
Size: Cardinal;
Re:Boolean;
begin
Size := MAX_COMPUTERNAME_LENGTH+1;
Getmem(ComputerName,Size);
{retrieve computer name}
Re:=GetComputerName(ComputerName, Size);
if re then
Edit1.Text := StrPas(Computername)
else Showmessage('Computer Name Not Found');
Freemem(ComputerName);
end;
大体步骤:
1:先创建一个窗体。
2:将一个label1,一个按扭 bitbtn1,bittn2 放入窗体。
3:对BITBTN1 的ONCLICK 事件编程。
编程如下:
.......
var
tp:ttcpclient;
strname,straddr:string;
begin
tp:=ttcpclient.create(self);
tp.close;
tp.open;
strname:=tp.LocalHostName;
straddr:=tp.LocalHostAddr;
label1.caption:=strname+' IP: '+straddr;
tp.close;
end;
bitbtn2 的onclick 事件如下:
.....
begin
close;
end; 如上程序,运行后,单击bitbtn1 按扭, label1 将显示出本地计算机的 IP地址 和计算机名。(完毕)
name:pchar;
size:dword;
begin
size:=255;
getmem(name,size);;
getcomputername(name,size);
showmessage(name);
freemem(name);
end;
err := WSAStartup( wVersionRequested, wsaData );
gHostName:='default';
if ( err = 0 ) then
if getHostName(HostName,10)=0 then
gHostName := HostName;
WSACleanup();
//原始代码,经过试用的哦。
记得在uses里面 家,winsock.
err := WSAStartup( wVersionRequested, wsaData );
gHostName:='default';
if ( err = 0 ) then
if getHostName(HostName,10)=0 then
gHostName := HostName;
WSACleanup();
//原始代码,经过试用的哦。
记得在uses里面 家,winsock.