dormky 2 Posted Monday at 02:19 PM In Data.DB, the dataset events are defined as TDataSetNotifyEvent = procedure(DataSet: TDataSet) of object; This means that such code as MyTableTest.BeforeDelete := procedure (d: TDataSet) begin LogTableOperation('MyTableTestBeforeDelete'); end; not valid. Is there anyway of casting this ? I'd rather not define a procedure in my data module for every event of every table... Share this post Link to post
David Heffernan 2357 Posted Monday at 02:48 PM 24 minutes ago, dormky said: Is there anyway of casting this ? No, they are fundamentally different things in terms of implementation. Share this post Link to post
Remy Lebeau 1459 Posted yesterday at 04:33 AM This is documented behavior: https://docwiki.embarcadero.com/RADStudio/en/Anonymous_Methods_in_Delphi Quote you cannot assign an anonymous method to a regular method pointer. Method references are managed types, but method pointers are unmanaged types. Thus, for type-safety reasons, assigning method references to method pointers is not supported. For instance, events are method pointer-valued properties, so you cannot use an anonymous method for an event. Share this post Link to post
JonRobertson 76 Posted 18 hours ago On 1/20/2025 at 8:19 AM, dormky said: I'd rather not define a procedure in my data module for every event of every table... If several tables will use events with identical functionality, such as logging, you can have a single event assigned to multiple tables: procedure TForm1.AllTablesBeforeDelete(DataSet: TDataSet); begin LogTableOperation(DataSet.Name + 'BeforeDelete'); end; MyTable1Test.BeforeDelete := AllTablesBeforeDelete; MyTable2Test.BeforeDelete := AllTablesBeforeDelete; MyTable3Test.BeforeDelete := AllTablesBeforeDelete; Or assign the event handler to each table using the object inspector. Share this post Link to post