Recent

Author Topic: Runtime assignment of event handler  (Read 8682 times)

eric

  • Sr. Member
  • ****
  • Posts: 267
Runtime assignment of event handler
« on: March 12, 2004, 11:19:00 am »
How do you assign an event handler to a component at runtime? In Delphi and Kylix you use something like:

Component2.OnChange := Component1Change;

but this fails to compile in Lazarus with "Not enough parameters". What parameters are required?

Eric

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Runtime assignment of event handler
« Reply #1 on: March 12, 2004, 03:17:20 pm »
In objfpc mode (the deault mode for lazarus, use
Component2.OnChange := @Component1Change;

if you don't use '@', fpc assigns the result of Component1Change to the OnChange event.
Component1Change has parameters and in your code no parameters were given. Hence the error message.

You also can use {$mode delphi}. FPC tries to be delphi compatible and your code will probably work.

HTH,
Vincent.

eric

  • Sr. Member
  • ****
  • Posts: 267
Runtime assignment of event handler
« Reply #2 on: March 12, 2004, 05:03:50 pm »
Oh I see. Thanks very much.

Eric

 

TinyPortal © 2005-2018