Object Method Pointers

contains all delphi packages mentioned below
Post Reply
JonnyBoy
Posts: 1
Joined: Fri Nov 13, 2009 6:48 pm

Object Method Pointers

Post by JonnyBoy »

I want to write a generic event pointer saver that I can use and then restore method pointers.

In other words I want to write something like this:

Code: Select all


procedure TForm1.Memo1Change(Sender: TObject);
var
  EventSaver : TEventSaver;
begin
  EventSaver.Create(Memo1.OnChange);
  Memo1.Lines.Append('This is a new line.');
  EventSaver.Free;
end;

I don't want to have to worry about the method prototype. I just want to save the method pointer from any object and any event and automatically restore it on free.

I already have such an object but it requires that I pass the type of TNotifyEvent. If I want non-standard events I have to add them to my class.

Thanks for any ideas on how to do this. :-)
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You can probably typecast to "TMethod"? Maybe that helps? But I have to say that Delphi *is* very strict with method types. You could also try using "constructor TEventSaver.Create(var method);". Not sure if that works. If it compiles, of course then you'd have to use pointer math etc...
healthins
Posts: 1
Joined: Mon May 24, 2010 6:16 pm
Location: USA
Contact:

hi

Post by healthins »

Create class of that object and then pointer of that object.
Post Reply