begin
winexec('ipconfig',sw_show);
end;我想点一下按钮来查看我自己的ip地址,可是它一闪就过去了,请问如何办?

解决方案 »

  1.   

    function GetLocalIP:string;
    type
      TaPInAddr = array [0..10] of PInAddr;
      PaPInAddr = ^TaPInAddr;
    var
      phe  : PHostEnt;
      pptr : PaPInAddr;
      Buffer : array [0..63] of char;
      I    : Integer;
      GInitData      : TWSADATA;
    begin
      WSAStartup($101, GInitData);
      Result := '';
      GetHostName(Buffer, SizeOf(Buffer));
      phe :=GetHostByName(buffer);
      if phe = nil then Exit;
      pptr := PaPInAddr(Phe^.h_addr_list);
      I := 0;
      while pptr^[I] <> nil do begin
        result:=StrPas(inet_ntoa(pptr^[I]^));
        Inc(I);
      end;
      WSACleanup;
    end;
      

  2.   

    Uses
      WinSock;function GetLocalIP:string;
    type
      TaPInAddr = array [0..10] of PInAddr;
      PaPInAddr = ^TaPInAddr;
    var
      phe  : PHostEnt;
      pptr : PaPInAddr;
      Buffer : array [0..63] of char;
      I    : Integer;
      GInitData      : TWSADATA;
    begin
      WSAStartup($101, GInitData);
      Result := '';
      GetHostName(Buffer, SizeOf(Buffer));
      phe :=GetHostByName(buffer);
      if phe = nil then Exit;
      pptr := PaPInAddr(Phe^.h_addr_list);
      I := 0;
      while pptr^[I] <> nil do begin
        result:=StrPas(inet_ntoa(pptr^[I]^));
        Inc(I);
      end;
      WSACleanup;
    end;
      

  3.   

    我建立了一个最基本的form1,然后把uses,type,var,和begin后面的分别插入进去,它报个错,expected':'but'='found,就这个
      

  4.   

    呵呵。兄弟,这次再不懂我可就没招了。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, WinSock, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      
    function GetLocalIP:string;implementation{$R *.dfm}
    function GetLocalIP:string;
    type
      TaPInAddr = array [0..10] of PInAddr;
      PaPInAddr = ^TaPInAddr;
    var
      phe  : PHostEnt;
      pptr : PaPInAddr;
      Buffer : array [0..63] of char;
      I    : Integer;
      GInitData      : TWSADATA;
    begin
      WSAStartup($101, GInitData);
      Result := '';
      GetHostName(Buffer, SizeOf(Buffer));
      phe :=GetHostByName(buffer);
      if phe = nil then Exit;
      pptr := PaPInAddr(Phe^.h_addr_list);
      I := 0;
      while pptr^[I] <> nil do begin
        result:=StrPas(inet_ntoa(pptr^[I]^));
        Inc(I);
      end;
      WSACleanup;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(GetLocalIP);
    end;end.