频道分类

Delphi 获取计算机名称3

作者:admin 来源: 日期:2019/10/8 10:55:47 人气: 标签:

 
function GetComputerName: string;
var
  buffer: array [0 .. MAX_COMPUTERNAME_LENGTH + 1] of Char;
  Size: Cardinal;
begin
  Result := 'N/A';
  Size := MAX_COMPUTERNAME_LENGTH + 1;
  Winapi.Windows.GetComputerName(@buffer, Size);
  Result := StrPas(buffer);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
form1.Caption:=GetComputerName;
end;