Re: tIdHttp and tThread

Giganews Newsgroups
Subject: Re: tIdHttp and tThread
Posted by:  Remy Lebeau (TeamB) (gambit…@yahoo.com)
Date: Thu, 2 Oct 2003

"Jack Cane" <jwca…@mindspring.com> wrote in message
news:55B44CB12481E240jwca…@mindspring.com...
> Problem is, tIdHttp.Create() takes an argument of tComponent,
> whereas my thread object is of type tThread.

Simply specify 'nil' as the constructor's parameter.  The purpose of the
Owner parameter when constructing a component is to specify the owning
component that is responsible for freeing the new component instance.  If
you specify 'nil' as the Owner, then your own code needs to free the
component instance when you are done with it.  Simply add a destructor to
your TThread and free the TIdHTTP instance from there.  Make sure that the
TIdHTTP instance is declared as a member of your Tthread class.  For
example:

    class TMyThread = class(TThread)
    private
        FHttp: TIdHTTP;
    public
        constructor Create(CreateSuspended: Boolean); override;
        destructor Destroy; override;
    end;

    constructor TMyThread.Create(CreateSuspended: Boolean);
    begin
        FHttp := TIdHTTP.Create(nil);
        inherited Create(CreateSuspended);
    end;

    destructor TMyThread.Destroy;
    begin
        FHttp.Free;
    end;

Gambit

Replies

None

In response to

tIdHttp and tThread posted by Jack Cane on Thu, 2 Oct 2003