0% found this document useful (0 votes)
598 views

Simulating Multicast Events in Win32 Delphi

This document discusses simulating multicast events in Win32 Delphi applications. It explains that in Win32 Delphi, only one method can be assigned as an event handler, while Delphi for .NET allows multiple handlers. It then provides an example class that maintains a list of methods bound to its events, simulating multicast handling by calling all methods when an event fires. Code is presented to define the class with its event type and list of handlers, as well as methods to add, remove, and fire event handlers.

Uploaded by

Peter Baek
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
598 views

Simulating Multicast Events in Win32 Delphi

This document discusses simulating multicast events in Win32 Delphi applications. It explains that in Win32 Delphi, only one method can be assigned as an event handler, while Delphi for .NET allows multiple handlers. It then provides an example class that maintains a list of methods bound to its events, simulating multicast handling by calling all methods when an event fires. Code is presented to define the class with its event type and list of handlers, as well as methods to add, remove, and fire event handlers.

Uploaded by

Peter Baek
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Simulating multicast events in Win32 Delphi

In Win32 Delphi OOP, only one method can be assigned as a handler to a


component's event. In Delphi for .Net, multiple event handlers can be
bound to the same event. Here's a simulation of multicast events in Win32
Delphi.

More of this Feature


• Download Source Code

When you develop (Win32) applications using Delphi you Join the Discussion

almost always write the code to handle some "Post your views, comments,
questions and doubts to this
component's event(s). For example, when you drop a article."
Discuss!
TButton on a form and double click it, an empty event
Related Resources
handler is created where you write the code to react on • OOP in Delphi
• Simulating class properties in
the user click action. Win32 Delphi
• Language features in Delphi
Win32 Delphi allows you to assign only one method as a for .NET

handler to an event of a component.

With Delphi for .NET a notion of multicast events was introduced. A developer can
assign two or more methods to be called when an event gets fired.

Let's see how to build a Win32 Delphi object that maintains a list of the methods its
event(s) is handled by - thus creating a simulation of multicast event handling.
Before we start, I strongly suggest that you freshen up your Delphi OOP and
custom component development memory...

A simple example of multicast event handling in Win32 Delphi


First, we'll define a simple class (TMultiEventClass) with only one event of
TMutliEvent type. In order to store a list of methods that will be called when event
is fired (using the FireMultiEvent) we'll use a fMultiEventHandlers TList object. The
TList Delphi class is designed to be used as a storage mechanism for an array of
pointers.
By design, each method (function or procedure) in Delphi code can be represented
with a TMethod Delphi type. A TMethod type can be used, for example, to execute a
method by its name.
type

  PMethod = ^TMethod;

  TMutliEvent = procedure(const Value : string) of 
object;

  TMultiEventClass = class

  private

    fMultiEventHandlers : TList;

  public

    constructor Create;

    destructor Destroy; override;

    procedure AddMultiEvent(const Value: TMutliEvent);

    procedure RemoveMultiEvent(const Value: 
TMutliEvent);

    procedure FireMultiEvent;

  end;
Related Articles

• Implementing MultiCast Events for Win32 Delphi's TDataset and


TField De...
• Dynamically set event handlers to Delphi controls NOT being
inherited from ...
• How to Detach an Event Handler from a Delphi Control Event
• Get the list of events with attached event handlers (Delphi for
Win32)
• Learn about: properties, events and Delphi Pascal - Page 2/2

Guide since 1998

Zarko Gajic
Delphi Programming Guide

• Sign up for my Newsletter

• My Blog
• My Forum

You might also like