Suspicious typecast of string to PAnsiChar

Giganews Newsgroups
Subject:Suspicious typecast of string to PAnsiChar
Posted by: eko indriyawan
Date:Mon, 30 Nov 2009

I have a problem with my code. My code is like shown below:

{code: delphi}
....
....
var
  WSAData: TWSAData;
  HostEnt: PHostEnt;
  Name: string;
  Address: string;

begin

WSAStartup(2, WSAData);
SetLength(Name, 255);
Gethostname(PAnsiChar(Name), 255);
SetLength(Name, StrLen(PAnsiChar(Name)));

HostEnt := gethostbyname(PAnsiChar(Name));

with HostEnt^ do
  Address := Format('%d.%d.%d.%d', [

    Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);

WSACleanup;

VIPClient := Address;
VNamaClient := Name;

end;
....
....
{code}

From code above, everytime I try to compile or build always raise the warning:

*[DCC Warning] UPROC.pas(356): W1044 Suspicious typecast of string to PAnsiChar*

please advise....

Regards,

Eko Indriyawan

Replies