Peter,

> -----Original Message-----
> Hi folks,
>   Ok, something snafued here and I've lost track of both the
> handy "Get local machine's IP #' methods which two people
> kindly posted a few day's back.
>
> Er, might I have one or both again please? <g>


Don't have a copy of the previous post, but this is what I use.  Works in
D1 - D4.  With D1, you will need to get the WinSock.Pas from D2 and hack
that to work under D1.  A bit long but if you don't need to support D1, you
can bracket code out.

function TWindowsSocket.GetLocalHostName: string;
var
  a: array [1..256] of Char;
  pc: PChar;
begin
  pc := @(a[1]);
  if WinSock.gethostname (pc, 255) = 0 then begin
    Result := StrPas (pc);
  end else begin
    Result := '';
  end; { if }
end; { TWindowsSocket.GetLocalHostName }

function TIPAddress.SetHostByName (value: string): Boolean;
type
  PINT = ^Iaddr;
var
  he: PHostEnt;
{$IFDEF Win32}
begin
  he := GetHostByName (PChar (value));
{$ELSE}
var
  a: array [0..256] of Char;
  pc: PChar;
begin
  pc := @(a[0]);
  StrPCopy (pc, value);
  he := GetHostByName (pc);
{$ENDIF}

  if he = Nil then begin
    Result := False;
    Exit;
  end; { if }
  InternetAddress := PINT(Pointer(he^.h_addr_list)^)^;
  Result := True;
end; { TIPAddress.SetHostByName }


Regards,
Dennis.

---------------------------------------------------------------------------
  New Zealand Delphi Users group - Offtopic List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to