Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Fehler:"Incompatible types: 'Array' and 'PAnsiChar' (https://www.delphipraxis.net/164713-fehler-incompatible-types-array-pansichar.html)

Lyan 26. Nov 2011 10:44

Delphi-Version: 2010

Fehler:"Incompatible types: 'Array' and 'PAnsiChar'
 
Hallo hat jemand eine Idee wieso der o.g. Fehler auftritt?

Code:
function sLocalIP: string;
var phoste: PHostEnt;
    Buffer: array [0..100] of char;
    WSAData: TWSADATA;
begin
  result := '';
  if WSAStartup($0101, WSAData) <> 0 then exit;
    GetHostName(Buffer,Sizeof(Buffer)); //Error1
  phoste:=GetHostByName(buffer);//Error2
  if phoste = nil then
    result := '127.0.0.1'
  else
    result := StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
  WSACleanup;
end;
Danke im vorraus



EDIT:// Hat sich erledigt!

Lösung zum Problem:

function sLocalIP: string;
var phoste: PHostEnt;
Buffer: array [0..100] of char;
WSAData: TWSADATA;
begin
result := '';
if WSAStartup($0101, WSAData) <> 0 then exit;
GetHostName(@Buffer,Sizeof(Buffer)); //Error1
phoste:=GetHostByName(@buffer);//Error2
if phoste = nil then
result := '127.0.0.1'
else
result := StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
WSACleanup;
end;

himitsu 26. Nov 2011 14:41

AW: Fehler:"Incompatible types: 'Array' and 'PAnsiChar'
 
GetHostByName gibt es nur als ANSI-Version.

PChar ist also falsch, vorallem seit Delphi 2009, da dort PChar = PWideChar. :warn:


Mit deinem D2010 müßtest du also jetzt immernoch eine Warnung bekommen, welche man nicht ebenfalls überhören sollte.


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:20 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz