Solved

List of events

Posted on 1997-12-21
8
169 Views
Last Modified: 2012-05-04
How do I fire events stored in a TList ?
0
Comment
Question by:miv
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1354325
What exactly do you mean ? Do you want to fire multiple event handlers for one event stored in a TList, or event handlers for different events stored in this list ?
0
 
LVL 1

Author Comment

by:miv
ID: 1354326
option 2
0
 
LVL 4

Expert Comment

by:d003303
ID: 1354327
Yo,

maybe you could explain a bit why you need to store the event handlers in a TList. That would help to make a better answer.
Basically it is only typecast. Lets assume that the stored event is a TNotifyEvent, here is a quick example :

   TMyObject = class(TObject)
     FEventList: TList;
     FEventCount: Integer;
     constructor Create;
     destructor Destroy; override;
     procedure SetOnClick(NewValue : TNotifyEvent);
     function GetOnClick: TNotifyEvent;
     property OnClick: TNotifyEvent read GetOnClick write SetOnClick;
   end;

constructor TMyObject.Create;
var Index : Integer;
begin
  inherited Create;
  FEventList := TList.Create;
  FEventCount := 1;
  for Index := 0 to FEventCount - 1
   do FEventList.Add(nil);
end;

destructor TMyObject.Destroy;
begin
  FEventList.Free;
  inherited Destroy;
end;

procedure TMyObject.SetOnClick(NewValue : TNotifyEvent);
begin
  FEventList[0] := @NewValue;
end;

function TMyObject.GetOnClick: TNotifyEvent;
var FEvent : TNotifyEvent;
begin
  @FEvent := FEventList[0];
  Result := FEvent;
end;

Fireing events would be like the code in GetOnClick, but better check first if the pointer is not nil.

Hope this helps,

Slash/d003303
0
 
LVL 1

Author Comment

by:miv
ID: 1354328
Ok, I´ll try to explain exactly what I want:

I have an object which on modification of some vars need to notify all the viewers which is viewing the object.

The viewers has added their "OnReshow" event to the "NotificationList" on the object.

I want to traverse the NotificationList and fire all the events on the list.

But as the list only knows that it is containing pointers, it can´t treat them as events. Have tried typecasting, but get compiler errors everytime...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Accepted Solution

by:
d003303 earned 50 total points
ID: 1354329
Yo,

the typecast you need is in the GetOnClick-method. This converts the pointers to the event methods.

You could also use it like

var FEvent : TNotifyEvent;
    Index : Integer;
begin
  for Index := 0 to FEventList.Count - 1 do
   if FEventList[Index] <> nil then
    begin
      @FEvent := FEventList[Index];
      FEvent(Self);
    end;
end;

to fire all events stored in FEventList.

0
 
LVL 1

Author Comment

by:miv
ID: 1354330
Hi,
It was to fast to accept that answer.

The FEvent seems to pointing no where (or maybe into the ROM :-) when I fire it...

Any suggestions ?

  Michael
0
 
LVL 4

Expert Comment

by:d003303
ID: 1354331
Yo,

to help you on that I need some sample code where the event list is filled, and where the events are fired.

Slash/d003330
0
 
LVL 1

Author Comment

by:miv
ID: 1354332
Hi,
It´s ok. I created a dummy object with one attribut and added that object to the list instead. That works but´s a bit of a workaround.
I can´t post my code, you´ll need apx. 70000 lines to reconstruct the error :-(

Thanks for the help anyway, you earned your points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 75
Delphi 2 46
Dev Express grid collapse 2 39
Graphics32 under Delphi 10.1 Berlin 2 34
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now