- Регистрация
- 1 Мар 2015
- Сообщения
- 1,467
- Баллы
- 155
The Unit WinInet must be included.
Код:
type
TEasyURLComponents = record
Scheme, HostName: string;
Port: Integer;
User, Password, UrlPath, ExtraInfo: string;
end;
procedure CrackURL(const URL: string; decode, escape: Boolean; var data: TEasyURLComponents );
var
uc: TURLComponents;
flags: Cardinal;
begin
ZeroMemory(@uc, sizeof(uc));
uc.dwStructSize := sizeof(TURLComponents);
with data do
begin
SetLength(Scheme, 10);
uc.lpszScheme := PChar(Scheme);
uc.dwSchemeLength := Length(Scheme);
SetLength(HostName, 200);
uc.lpszHostName := PChar(HostName);
uc.dwHostNameLength := Length(HostName);
SetLength(User, 200);
uc.lpszUserName := PChar(User);
uc.dwUserNameLength := Length(User);
SetLength(Password, 200);
uc.lpszPassword := PChar(Password);
uc.dwPasswordLength := Length(Password);
SetLength(UrlPath, 1000);
uc.lpszUrlPath := PChar(UrlPath);
uc.dwUrlPathLength := Length(UrlPath);
SetLength(ExtraInfo, 2000);
uc.lpszExtraInfo := PChar(ExtraInfo);
uc.dwExtraInfoLength:= Length(ExtraInfo);
end;
flags := 0;
// Converts encoded characters back to their normal form.
if decode then flags := flags or ICU_DECODE;
// Converts all escape sequences (%xx) to their corresponding characters.
if escape then flags := flags or ICU_ESCAPE;
if not InternetCrackUrl(PChar(URL), Length(URL), flags, uc) then
RaiseLastWin32Error;
with data do
begin
SetLength(Scheme, uc.dwSchemeLength);
SetLength(HostName, uc.dwHostNameLength);
SetLength(User, uc.dwUserNameLength);
SetLength(Password, uc.dwPasswordLength);
SetLength(UrlPath, uc.dwUrlPathLength);
SetLength(ExtraInfo, uc.dwExtraInfoLength);
Port := uc.nPort;
end;
end;