Board index » delphi » Problem with Event Handling in Indy

Problem with Event Handling in Indy

Hi,

I'm trying to "Encapsulate" ftp and http file transfer and have the
same set of basic functions for both... Eg: Connect, Disconnect, Get,
Etc...

All basic functions are working but none of the Event Handlers works.
I don't understand why events are never arising.

====================
unit netUnit;
TNet = class(TComponent)
  http: TIdHTTP;
  ftp  : TIdFTP;
  IdAntiFreeze1: TIdAntiFreeze;
  procedure ftpWork(Sender: TObject; AWorkMode: TWorkMode;
    const AWorkCount: Integer);
 (...)
public
  (...)
  function Connect     : boolean;
  function Disconnect : boolean;
  function Get(const NetName,LocalName : string) : boolean;
end;

implementation

procedure TNet.ftpWork(Sender: TObject; AWorkMode: TWorkMode;
  const AWorkCount: Integer);
begin
  MessageDlg('ftp Working',mtInformation,[mbOk],0);
end;
=====================
=====================
uses netUnit
var net : TNet;
begin
  net := TNet.Create(ftp-host,username,password);
  net.connect;
  net.get('path/filename','filename');
  net.Disconnect;
  net.free;  
end.

In the simplified example above, my program will properly
 connect,
 get the file
 Disconnect
 Free the object.

But ftp.OnWork (as any other Event) arised. Actually TComponent events
are not arising either.

 

Re:Problem with Event Handling in Indy


Quote
> All basic functions are working but none of the Event Handlers works.
> I don't understand why events are never arising.
> TNet = class(TComponent)
>   http: TIdHTTP;
>   ftp  : TIdFTP;
>   IdAntiFreeze1: TIdAntiFreeze;
>   procedure ftpWork(Sender: TObject; AWorkMode: TWorkMode;
>     const AWorkCount: Integer);
>  (...)

I can't see any code in your posted sample how TNet.ftpWork is being
triggered. Show us how you have connected it to TidFTP.OnWork

Olaf

Re:Problem with Event Handling in Indy


Hi Olaf,

On Tue, 4 Dec 2001 05:00:54 +0100, "Olaf Monien" <o...@monien.net>
wrote:

Quote
>> All basic functions are working but none of the Event Handlers works.
>> I don't understand why events are never arising.
>> TNet = class(TComponent)
>>   http: TIdHTTP;
>>   ftp  : TIdFTP;
>>   IdAntiFreeze1: TIdAntiFreeze;
>>   procedure ftpWork(Sender: TObject; AWorkMode: TWorkMode;
>>     const AWorkCount: Integer);
>>  (...)

>I can't see any code in your posted sample how TNet.ftpWork is being
>triggered. Show us how you have connected it to TidFTP.OnWork

Oh darn... I guess in the zillion things I've tried none were
connecting to the event. Actually, I tought existing event such as
OnWork were already connected. When I doubleclick on the IdFTP.OnWork
in the Property Editor the procedure ftpWork is declared in interface
and skeleton Implemented in Implementation  I previously made few
tests in other programs and it was enought to trigger the events.

How should I connect TidFTP.OnWork to trigger ftpWork procedure?

Thank you for you help and forgive my newbieness...

Simon.

Re:Problem with Event Handling in Indy


Quote
----- Original Message -----
From: "Simon Borduas" <sbord...@{*word*104}-force.ca>
To: <o...@monien.net>
Sent: Mittwoch, 5. Dezember 2001 16:32
Subject: Event handling problem

> Oh darn... I guess in the zillion things I've tried none were
> connecting to the event. Actually, I tought existing event such as
> OnWork were already connected. When I doubleclick on the IdFTP.OnWork
> in the Property/Event Editor the procedure ftpWork is declared in
> interface and skeleton Implemented in Implementation  I previously
> made few tests in other programs and it was enought to trigger the
> events.

> How should I connect TidFTP.OnWork to trigger ftpWork procedure?

Well there seems to be some kind of misunderstanding: You have a new class
"TNet" declared. This class has two private members:
http: TIdHTTP;
ftp  : TIdFTP;
Then you have declared a  procedure ftpWork (...) this is actually not an
event but only a simple method of the new TNet class. If you want to have an
event wich can be used by double clicking in object inspector you have to
put it in the "published" section
and (more important) it should be declared as:
 property OnWork: TWorkEvent read GetOnWork write SetOnWork;
(See TIdComponent in IdComponent.pas)

Then implement GetOnWork like:
...
Result:=ftp.OnWork;
...

and SetOnWork(aValue:TWorkEvent) like:
...
ftp.OnWork:=aValue
...

The same way you could do it for events from http

This is only one possibility, may be other guys have other ideas...

Olaf

Other Threads