Delphi : Convert Relative URL to Absolute URL

Nyari di mbah Google ga nemu2. Akhirna buat sendiri.

Uses WinInet;

procedure TruncateStr(var s : string);
var i : integer;
begin
for i := 1 to length(s) do
if (s[i]=#0) then
begin
setLength(s,i-1);
exit;
end;
end;

function GetAbsoluteURL(baseURL,URL:string):string;
var sz : dword;
begin
sz := 10240;
setLength(result,sz);
InternetCombineUrl(pchar(baseUrl),pchar(url),pchar(result),sz,ICU_BROWSER_MODE);
TruncateStr(result);
end;

Eg. GetAbsoluteURL(‘http://www.whatever.com/test/’,’/image.jpg’) hasilna http://www.whatever.com/image.jpg

Pos ini dipublikasikan di Delphi, Pengalaman dan tag . Tandai permalink.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s