![]() |
![]() ![]() ![]() |
acHTTP, acWebImage and acSQLQueryThread components.
|
type
|
TacHTTPDoneEvent = procedure(Sender: TObject;
|
const ContentType: String;
|
FileSize: Integer; Stream: TStream) of object;
|
|
property OnDone: TacHTTPDoneEvent;
|
The OnDone event occurs when the acHTTP component has successfully downloaded requested Web resource.
|
|
The component pass to the OnDone event handler 3 following parameters:
|
Parameters | Meaning
|
ContentType | the media type (also known as Multipurpose Internet Mail Extension (MIME) type) of requested document. For example if you downloaded usual text-file, the ContentType will be "text/plan". For HTML page ContentType will "text/html", for executable file "application/binary" and "image/jpeg" for JPEG, JPG and JPE files.
|
For more information about Internet media types, please read RFC 2045, 2046, 2047, 2048, and 2077 (http://www.oac.uci.edu/indiv/ehood/MIME/MIME.html). Check out also the Internet media type registry at ftp://ftp.iana.org/in-notes/iana/assignments/media-types;
|
FileSize | size of downloaded data in bytes;
|
Stream | the stream which contains downloaded data (this is actually TMemoryStream. Check out description of TMemoryStream class for more details on how to retreive data from it). ![]() |
procedure TForm1.acHTTP1Done(Sender: TObject;
|
ContentType: string; FileSize: Integer; Stream: TStream);
|
var
|
Str: String;
|
begin
|
if Stream = nil then
|
Exit; // can be already stored to file specified by OutputFileName
|
|
with TMemoryStream(Stream) do // yes, this is actually TMemoryStream
|
if OutToMemoBox1.Checked then // output to Memo1
|
begin
|
Memo1.Lines.LoadFromStream(Stream);
|
|
{ // alternatively:
|
SetLength(Str, Size);
|
Stream.Read(Str[1], Size); // or Move(Memory^, Str[1], Size);
|
Memo1.Text := Str; }
|
end
|
else
|
begin // save to file
|
Memo1.Text := 'Saved to c:\httptest.dat';
|
SaveToFile('c:\httptest.dat');
|
end;
|
|
StatusBar1.Panels[0].Text := 'Successfully downloaded ' + IntToStr(FileSize) + ' bytes';
|
end;
|
void __fastcall TForm1::acHTTP1Done(TObject *Sender,
|
AnsiString ContentType, int FileSize, TStream *Stream)
|
{
|
AnsiString Str;
|
|
if (Out1->Checked) {
|
Str.SetLength(Stream->Size);
|
Move(((TMemoryStream*)Stream)->Memory, &Str[1], Stream->Size);
|
Memo1->Text = Str;
|
}else {
|
Memo1->Text = "Saved to c:\httptest.dat";
|
((TMemoryStream*)Stream)->SaveToFile("c:\httptest.dat");
|
}
|
|
StatusBar1->Panels->Items[0]->Text = "Successfully downloaded " + IntToStr(FileSize) + " bytes";
|
}
|
OnProgress, OnHTTPError, OnHeaderInfo and OnDoneInterrupted events;
|
Read and Abort methods;
|
OutputFileName, OutputFileAttributes and FileName properties.
|