Ian Branch 127 Posted November 19, 2022 Hi Team, I have a TTable called JobTickets and I want to assign a Unit procedure to its AfterInsert event at run time. Something like.. JobTickets.AfterInsert(DataSet: TDataSet) := JobTicketsAfterInsert(DataSet: TDataSet); Delphi doesn't like the above. 😞 What do I need to do to make this happen please?  Regards & TIA, Ian Share this post Link to post
FPiette 383 Posted November 19, 2022 (edited) 27 minutes ago, Ian Branch said: Delphi doesn't like the above. You should tell us what is the EXACT error message the compiler give.  JobTickets.AfterInsert(DataSet: TDataSet) := JobTicketsAfterInsert(DataSet: TDataSet);  It is wrong. Probably it should be : JobTickets.AfterInsert := JobTicketsAfterInsert; 27 minutes ago, Ian Branch said: I want to assign a Unit procedure to its AfterInsert event at run time A "Unit procedure" is not a proper terminology. It is either a simple procedure or a method of object. The later is required. You should show the declaration of JobTicketsAfterInsert. That's probably where the error is. Edited November 19, 2022 by FPiette Share this post Link to post
Ian Branch 127 Posted November 19, 2022 Hi François All sorted. I have it working now. The thing I was doing wrong seems to be using the same event name that the component would use. I changed JobTicketsAfterInsert to MyJobTicketsAfterInsert. Added to the form class procedure MyJobTicketsAfterInsert(DataSet: TDataSet); Changed the procedure to procedure TdmC.MyJobTicketsAfterInsert(DataSet: TDataSet); begin // DataSet.FieldByName('DateIn').AsDateTime := now; // end; And the assignment to JobTickets.AfterInsert := MyJobTicketsAfterInsert; And it all works as desired.  Regards & Tks. Ian Share this post Link to post