Jump to content
Ian Branch

Assign an App procedure to a Component Event??

Recommended Posts

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
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 by FPiette

Share this post


Link to post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×