My class contains dataset (TDataSet). Users of my class can assign event handlers for this dataset:
ds.FieldByName('ID').OnChange := @ID_OnChange;
Then I have to reopen dataset:
ds.Close;
ds.Open;
After this all event handlers are gone:
if Assigned(ds.FieldByName('ID').OnChange) //returns false
So, I need to save handlers and restore them after reopen. I use TStringList for it:
var
EventHandlers: TStringList;
...
//I do this for every event of every field
if Assigned(ds.FieldByName('ID').OnChange) then
EventHandlers.AddObject('ID', @ds.FieldByName('ID').OnChange);
The problem is how to restore handlers:
ds.FieldByName('ID').OnChange := TFieldNotifyEvent(ObjToInt(EventHandlers.Objects[0]));//Invalid typecast error
How can I assign stored address to event handler? Thanks.
Integer
. An event handler is a method of object. That means it is two pointers. – Monomerous