Files
ProgressQuest/Web.pas
T
Eric Fredricksen 51792e632d [contents of README]
ProgressQuest v6.2(probably pre-release)
-----------------------------------------
This directory represents an ex post facto rendering of pq6 in its
various versions in svn, so that changes will be trackable thataway.

The version as of this moment in svn is 6.2, but this is probably not
the final 6.2. That will come in the next checkin.

(I didn't add this file in PQ 6.0, but after that you can use this README
to trace the checkin history using svn.)
2006-12-24 20:08:53 +00:00

50 lines
1.4 KiB
ObjectPascal

unit Web;
interface
uses
Windows, Messages, SysUtils, Classes, WinInet;
type
EWebError = class(Exception);
function DownloadString(const Url: string): string;
implementation
function DownloadString(const Url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of Char;
BytesRead: dWord;
begin
Result := '';
NetHandle := InternetOpen('PQ6.2', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url),
nil, 0, // headers
INTERNET_FLAG_RELOAD or
INTERNET_FLAG_PRAGMA_NOCACHE or
INTERNET_FLAG_NO_UI,
0);
if Assigned(UrlHandle) then begin
repeat
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer)-1, BytesRead);
Buffer[BytesRead] := #0;
Result := Result + Buffer;
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end else begin
raise EWebError.CreateFmt('Cannot open URL %s', [Url]);
end;
InternetCloseHandle(NetHandle);
end else begin
// NetHandle is not valid. Raise an exception
raise EWebError.Create('Unable to initialize internet API');
end;
end;
end.