title: Delphi XE4 - get your local IP in statusbar
body: <p>Seen most of the examples posted here but none seem to work on XE4. I am trying to display my IP in the status bar.</p>
  
  <pre><code>AdvOfficeStatusBar1.Panels[0].Text := GetIP;
  </code></pre>
  
  <p>Functions I have seen here mostly fail on xe4 as they were written in older delphi versions.I would like to get just the local IP,not the one behind the router. Well, for the sake of learning, it would be usefull to know that one too...:)</p>
  
  <p>I tried this :</p>
  
  <pre><code>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;
  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] &lt;&gt; nil do
     begin
       result:=StrPas(inet_ntoa(pptr^[i]^));
       Inc(i);
     end;
     WSACleanup;
  end; 
  </code></pre>
  
  <p>but it would not work .... many others too ... Seems i am missing something,but what?</p>
  
  <p>Tried this too :</p>
  
  <pre><code>function getIPs: Tstrings;
  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 := TstringList.Create;
    Result.Clear;
    GetHostName(Buffer, SizeOf(Buffer));
    phe := GetHostByName(buffer);
    if phe = nil then Exit;
    pPtr := PaPInAddr(phe^.h_addr_list);
    I    := 0;
    while pPtr^[I] &lt;&gt; nil do
    begin
      Result.Add(inet_ntoa(pptr^[I]^));
      Inc(I);
    end;
    WSACleanup;
  end; 
  </code></pre>
  
  <p>wont work stops on :  (GetHostName(Buffer, SizeOf(Buffer));</p>
  
  <p>This however WORKS !  :</p>
  
  <pre><code>Function GetIPAddress: String;
  type pu_long = ^u_long;
  var varTWSAData : TWSAData;
  varPHostEnt : PHostEnt;
  varTInAddr : TInAddr;
  namebuf : Array[0..255] of ansichar;
  begin
  try
  try
  If WSAStartup($101,varTWSAData) &lt;&gt; 0 Then
  Result := ''
  Else Begin
  gethostname(namebuf,sizeof(namebuf));
  varPHostEnt := gethostbyname(namebuf);
  varTInAddr.S_addr := u_long(pu_long(varPHostEnt^.h_addr_list^)^);
  Result := inet_ntoa(varTInAddr);
  End;
  except
  Result := '';
  end;
  finally
  WSACleanup;
  end;
  end;
  </code></pre>