Forum > General

Runtime assignment of event handler

(1/1)

eric:
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:
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:
Oh I see. Thanks very much.

Eric

Navigation

[0] Message Index

Go to full version