Delphi获取计算机名

代码实现如下

procedure TMainForm.tmrMonitorTimer(Sender: TObject);
var
  ComputerName:array[0..MAX_COMPUTERNAME_LENGTH+1] of char; //保留计算机名的缓冲区
  Buffer:Dword; // 缓冲区大小
  sComputerName:string;//计算机名
begin
  Buffer:=MAX_COMPUTERNAME_LENGTH+1;
  if GetComputerName(@ComputerName,Buffer)   then
    begin
      sComputerName:=ComputerName;
    end
  else
    begin
      sComputerName:='';
    end;
  ShowMessage(sComputerName);

end;