Autor Beitrag
Hänsel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 144



BeitragVerfasst: So 05.11.17 22:50 
Hallo, kann jemand helfen?

Ich habe Delphi10 und möchte in meinem Programm die IP-Adresse angezeigt bekommen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm_Start.Button1Click(Sender: TObject);
Function GetIPAdress: string;
var  phoste :PHostEnt;
     Buffer :array [0..100of char;
     WSAData :TWSADATA;
begin
result :='';
if WSAStartup($0101,WSAData)<> 0  then exit;
GetHostName(Buffer,SizeOf(Buffer));
phoste:=GetHostByName(buffer);
if phoste =nil then
 begin
 result:='99' ;
 end
 else
 Begin
 result :=StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
 WSACleanup;
 End;

Als Fehlermeldung kommt:
ausblenden Quelltext
1:
[dcc32 Fehler] Unit_Start.pas(114): E2010 Inkompatible Typen: 'PAnsiChar' und 'array[0..100] of Char'					

Was muss ich da ändern, oder gibt es eine andere Lösung um die aktuelle IP-Adresse zu bekommen.


Hänsel

Moderiert von user profile iconNarses: Delphi- und Code-Tags zuhingefügt.
Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am So 05.11.2017 um 21:55
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.17 23:03 
Moin!

Schau mal hier, da ist auch ein HostByName-Wrapper (sogar zwei) enthalten. :les: ;)

Und noch ein Hinweis: es gibt nicht die IP-Adresse eines Hosts, da ein Host auch mehrere Adressen haben kann. :idea: In der Regel hat man das heute auch standardmäßig, denn nach einem Windows-Standard-Setup hat man mindestens eine IPv4- und IPv6-Loopbackadresse. Dazu kommen dann noch die Adressen einer eventuellen Netzwerkkarte, etc. (2. NW-Karte, VPN-Adapter, usw.)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.