// returns ISP assigned IP
function LocalIP : 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; 
type
TaPInAddr = Array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: Array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
IP: String;
begin
Screen.Cursor := crHourGlass;
try
WSAStartup($101, GInitData);
IP:='0.0.0.0';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then
begin
ShowMessage(IP);
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^[I] <> nil do    //& 这错
begin
IP := inet_ntoa(pptr^[I]^);
Inc(I);
end;
WSACleanup;
getip:=ip;                      //getip 提示错
ShowMessage(IP);//如果上网则为上网ip否则是网卡ip
finally
Screen.Cursor := crDefault;
end;
end; 提示
  [错误] Unit1.pas(44): Illegal character in input file: '&' ($26)
  [错误] Unit1.pas(74): Illegal character in input file: '&' ($26)
  [错误] Unit1.pas(80): Undeclared identifier: 'getip'请问怎么修改,是不是DELPHI不支持这种符号?

解决方案 »

  1.   

    while pPtr^[I] <> nil do    //& 这错
    begin
    IP := inet_ntoa(pptr^[I]^);
    Inc(I);
    end; 
      

  2.   

    getip:=ip;  
    ----------->
    Result:=ip;
      

  3.   

    &lt;&gt;乱码,楼主是不是粘贴过来的代码呀
    看样子这应该是判断条件
      

  4.   

    getip:=ip;  
    -----------> 
    Result:=ip;什么意思,
    getip:=ip;                      //getip 提示错 
    ShowMessage(IP);//如果上网则为上网ip否则是网卡ip 
    Result:=ip;
    我这样改也不行,直接变成
    Result:=ip;
    ShowMessage(IP);//如果上网则为上网ip否则是网卡ip 
    也提示错,
    那位高手是什么意思?前面的&问题已经解决
      

  5.   


    代码不完整,没有定义函数。
    function LocalIP : 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;function GetIp: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;
        IP: String;
    begin
        Screen.Cursor := crHourGlass;
        try
            WSAStartup($101, GInitData);
            IP:='0.0.0.0';
            GetHostName(Buffer, SizeOf(Buffer));
            phe := GetHostByName(buffer);
            if phe = nil then
            begin
                ShowMessage(IP);
                Exit;
            end;
            pPtr := PaPInAddr(phe^.h_addr_list);
            I := 0;
            while pPtr^[I] <> nil do    //& ??
            begin
                IP := inet_ntoa(pptr^[I]^);
                Inc(I);
            end;
            WSACleanup;
            Result:=ip;                      //getip ???
            ShowMessage(IP);//????????ip?????ip
        finally
            Screen.Cursor := crDefault;
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        Label1.Caption:=GetIp;
    end;