What did i Miss
The original code says this:
buffer[rSize] = '\0';
You just did:
Didn't you get an error on that line ????
ALWAYS show errors you get.
And you don't put the buffer into result.
You could do something like this:
function myIPAddress(): string;
var
pSession: HINTERNET;
hFile: HINTERNET;
buffer: array[0..1023] of char; // make this an char-array
bytesRead: DWORD;
begin
Result := 'error';
pSession := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
hFile := InternetOpenUrlA(pSession, 'http://ip.thaddy.com/', nil, 0, INTERNET_FLAG_RELOAD, 0);
if InternetReadFile(hFile, @buffer, SizeOf(buffer), bytesRead) then // don't forget to check for error
begin
buffer[bytesRead] := #0; // set the last char in the string to #0
Result := Buffer; // put the buffer in result
end;
end;
Although I would do it something like this:
function myIPAddress: string;
var
pSession: HINTERNET;
hFile: HINTERNET;
bytesRead: DWORD;
TempIP: string;
begin
Result := 'error';
SetLength(TempIP, 1024);
pSession := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
hFile := InternetOpenUrlA(pSession, 'http://ip.thaddy.com/', nil, 0, INTERNET_FLAG_RELOAD, 0);
if InternetReadFile(hFile, PChar(TempIP), 1024, bytesRead) then
begin
SetLength(TempIP, bytesRead);
Result := TempIP;
end;
end;
Also... you can search the forum for some better versions.