![]() |
Delphi-Version: 2010
Fehler:"Incompatible types: 'Array' and 'PAnsiChar'
Hallo hat jemand eine Idee wieso der o.g. Fehler auftritt?
Code:
Danke im vorraus
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; 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; |
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