请问下,如何取得本机计算机名。急用。
程序是怎么样的。

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
        ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char;
        Size:Cardinal;
    begin
        Size:=MAX_COMPUTERNAME_LENGTH+1;
        GetComputerName(ComputerName,Size);
        ShowMessage(StrPas(ComputerName));
    end;
      

  2.   

    GetComputerName取得当前系统的计算机名. API原型:
    BOOL GetComputerName(    lpBuffer, // address of name buffer 
        LPDWORD nSize  // address of size of name buffer 
       );
     
    //Delphi
    function GetComputerName(lpBuffer: PChar; var nSize: DWORD): BOOL;
    ParameterslpBuffer
    Points to a buffer to receive the null-terminated character string containing the computer name. nSizePoints to a variable that specifies the maximum size, in characters, of the buffer. This value should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.  返回值:如果函数成功,返回非零值,
    及参数lpBuffer包含计算机名字符串(以#0为结束).
    参数nSize包含返回的计算机名的长度(不包含结束符#0).
    如果函数失败,返回零.如想得到错误信息,调用GetLastError.
      

  3.   

    用FastNet控件最快,官方下载地址:http://www.netmastersllc.com/方法:
       只用加一个NMDayTime组件,再加代码如下:
    procedure TForm1.botton1Click(Sender: TObject);
    begin
      edit1.Text:=NMDayTime1.LocalIP;
    end;
      

  4.   

    那又要怎么去取SQL服务器的名称呢???