'C:\ARSE\' is my temp directory :o)
Main Topics
Browse All TopicsI have a relatively simple question (simple for those Delphi gurus out there at least). I am using an Indy HTTP object to access an image from a map server on the net, saving the image to a file and then loading it in my application.
However, I would like to be able to run the HTTP request and save in a separate thread because it takes a while and my users can get stuff done while it goes about it's business. I would just maintain a link to the form that will load the image and when it is done, I would call a function with the filename to load.
I am also concerned about exception handling in the TidHTTP.Get(...) command.
A sample http link is (http://www.vwvortex.com/a
Currently I am using the following code (among other things I am doing):
responseStream:=TMemoryStr
httpIndy:=TIDHTTP.Create(n
httpIndy.Host:=host;
httpIndy.Request.ContentTy
httpIndy.Get(url,responseS
responseStream.SaveToFile(
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: StevenBPosted on 2004-02-10 at 18:44:02ID: 10328873
Something along these lines should get you started:
: TObject);
: TObject); ', 'http://www.vwvortex.com/a rtman/uplo ads/alpine .jpg', 'C:\ARSE\', 'Temp', LoadFinished);
Host, sURL, sPath, sFileName: String; aOnTerminate : TNotifyEvent);
pe := 'image/jpeg'; FPath + FFileName + '.jpg'); ;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TJPEGLoaderThread = class(TThread)
private
FHost, FURL, FPath, FFileName : string;
protected
procedure Execute; override;
public
constructor Create(sHost, sURL, sPath, sFileName : String; aOnTerminate : TNotifyEvent); reintroduce;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure LoadFinished(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
IdHTTP;
procedure TForm1.LoadFinished(Sender
begin
ShowMessage('Done');
end;
procedure TForm1.Button1Click(Sender
begin
TJPEGLoaderThread.Create('
end;
{ TJPEGLoaderThread }
constructor TJPEGLoaderThread.Create(s
begin
inherited Create(False);
FreeOnTerminate := True;
OnTerminate := aOnTerminate;
FHost := sHost;
FURL := sURL;
FPath := sPath;
FFileName := sFileName;
end;
procedure TJPEGLoaderThread.Execute;
var
ResponseStream : TMemoryStream;
HttpIndy : TIDHTTP;
begin
inherited;
ResponseStream := nil;
HttpIndy := TIDHTTP.Create(nil);
try
ResponseStream := TMemoryStream.Create;
HttpIndy.Host := FHost;
HttpIndy.Request.ContentTy
HttpIndy.Get(FURL , ResponseStream);
ResponseStream.SaveToFile(
finally
FreeAndNil(ResponseStream)
FreeAndNil(HttpIndy);
end;
end;
end.