在delphi5中如何用getcomputername()得到本地计算机名,请给源码

yyb2000 2000-06-19 03:44:00
...全文
130 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyb2000 2000-06-19
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: Tobject);
var
ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char;
Size: dword;
begin
{initialize the computer name size variable}
Size := MAX_COMPUTERNAME_LENGTH+1;

{retrieve the computer name}
if GetComputerName(ComputerName, Size) then

Edit1.Text := StrPas(Computername)
else Showmessage('Computer Name Not Found');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char; // holds the name
begin
{copy the specified name to the ComputerName buffer}
StrPCopy(ComputerName, Edit1.Text);

{set the computer name}
if SetComputerName(ComputerName) then

ShowMessage('Computer Name Reset Setting will be used at next startup')
else ShowMessage('Computer Name Not Reset');
end;

The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
yyb2000 2000-06-19
  • 打赏
  • 举报
回复
我是指用winapi getcomputername()
蝈蝈俊 2000-06-19
  • 打赏
  • 举报
回复
function ComputerName : String;

var
CNameBuffer : PChar;
fl_loaded : Boolean;
CLen : ^DWord;

begin

GetMem(CNameBuffer,255);
New(CLen);
CLen^:= 255;

fl_loaded := GetComputerName(CNameBuffer,CLen^);

if fl_loaded then
ComputerName := StrPas(CNameBuffer)
else
ComputerName := 'Unkown';

FreeMem(CNameBuffer,255);
Dispose(CLen);

end;

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧