Re: TidFTP: OnWork -> How to identify the TIdFTP-Object in Event? (its NOT Sende

Giganews Newsgroups
Subject: Re: TidFTP: OnWork -> How to identify the TIdFTP-Object in Event? (its NOT Sende
Posted by:  Remy Lebeau (TeamB) (gambit47.no.spam@no.spam.yahoo.com)
Date: Tue, 7 Oct 2003

"Niki Bugarcici" <Neik…@web.de> wrote in message
news:1F0D44EDC181E240Neik…@web.de...
> The "OnWork"-Event will return a TIdTCPClient-Object and
> NOT a TIdFTP-Object as "Sender".

That is because the FTP protocol uses a second connection for transfers,
thus TIdFTP uses a separate TIdTCPClient instance internally.

> I need the TIdFTP-Object or a way to come from TIdTCPClient
> to the correct TIdFTP...

There is no way to get the TIdFTP from the TIdTCPClient.  The TIdTCPClient
is created dynamically when needed and has no pointers to the owning TdFTP
at all.

The TIdFTP's OnWork event handler is assigned to the internal TIdTCPClient's
OnWork event.  If both the TIdFTP instance and the OnWork event handler are
members of the same thread class, then you don't need to use the Sender as
all, just access the TIdFTP member directly since you only have one per
thread, ie:

    TMyThread = class(TThread)
    private
        FTPClient: TIdFTP;
        procedure FTPClientWork(Sender: TObject; AWorkMode: TWorkMode; const
AWorkCount: Integer);
    protected
        procedure Execute; override;
    public
        constructor Create(CreateSuspended: Boolean); override;
        destructor Destroy; override
    end;

    constructor TMyThread.Create(CreateSuspended: Boolean);
    begin
        FTPClient := TIdFTPClient.Create(nil);
        FTPClient.OnWork := FTPClientWork;
        inherited Create(CreateSuspended);
    end;

    destructor TMyThread.Destroy;
    begin
        FTPClient.Free;
        inherited Destroy;
    end;

    procedure TMyThread.Execute;
    begin
        // do whatever
    end;

    procedure TMyThread.FTPClientWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
    begin
        // use FTPClient directly as needed
    end;

Gambit

Replies

None

In response to

TidFTP: OnWork -> How to identify the TIdFTP-Object in Event? (its NOT Sender) posted by Niki Bugarcici on Wed, 8 Oct 2003