Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Prism Event Handler in Delphi (https://www.delphipraxis.net/102509-event-handler-delphi.html)

FaNIX 30. Okt 2007 09:14


Event Handler in Delphi
 
How do i set the event for a specific class event?

This is how it looks in VB.NET
Delphi-Quellcode:
        AddHandler FtpClient.MessageReceive, AddressOf FtpClient_MessageReceive
        AddHandler FtpClient.MessageSend, AddressOf FtpClient_MessageSend
Below is the hand coded event i want to assign to the class:
Delphi-Quellcode:
procedure FtpClient_Feedback(Sender : TObject; E : TKFP.Net.MessageArgs);
Here is the declaration of the class event:


http://img136.imageshack.us/img136/3082/29591014oc2.jpg

The following doesnt work:

Delphi-Quellcode:
 Fo_FtpClient.MessageReceive := FtpClient_Feedback;
I get the following errors:
[Pascal Error] u_fdn_FTP_Dot_Net.pas(93): E2298 read/write not allowed for CLR events. Use Include/Exclude procedure
[Pascal Error] u_fdn_FTP_Dot_Net.pas(93): E2035 Not enough actual parameters

[edit=Phoenix]Marked as a .NET topic. Mfg, Phoenix[/edit]

DP-Maintenance 30. Okt 2007 09:31

DP-Maintenance
 
Dieses Thema wurde von "Phoenix" von "Programmieren allgemein" nach "Object-Pascal / Delphi-Language" verschoben.
Delphi-Question -> Delphi board

sirius 30. Okt 2007 09:48

Re: Event Handler in Delphi
 
One problem could be that your Ftp_client_feedback is a simple procedure and the property Messagerecieve waits for a "procedure of object" (a method within a class)

Phoenix 30. Okt 2007 09:55

Re: Event Handler in Delphi
 
Nope. As the compiler says: In Delphi.NET you must use the Include/Exclude functions to add/delete Eventhandler. That's because in CLR you always have multicast delegates (you can add more than one handler to a single event at a given time), and Delphi does not know the += / -= syntax to add / remove a single handler from an event. So you have to use
Delphi-Quellcode:
Include(Event, Eventhandler);
or
Delphi-Quellcode:
Exclude(Event, Eventhandler);
instead of
Delphi-Quellcode:
Event := handler;
.
If you can understand a bit of german, then have a look at this excellent article from Sakura: http://www.delphipraxis.net/internal...=248261#248261


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz