Recent

Author Topic: How to change form callback dynamically?  (Read 3004 times)

trayres

  • Jr. Member
  • **
  • Posts: 92
How to change form callback dynamically?
« on: May 20, 2016, 06:02:28 pm »
Is there a way such that I can change a form's event callback at runtime?

I'd like to change the OnMouseDown event depending on the state of what's going on. That information is in the *.lfm file.

I think I'd just access the main form, and use the @notation for the address of a procedure. Am I on the right track here?

Stupid question, sorry.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1216
    • Burdjia
Re: How to change form callback dynamically?
« Reply #1 on: May 20, 2016, 06:13:46 pm »
Just assign it:
Code: Pascal  [Select][+][-]
  1.   PROCEDURE TForm1.Whatever;
  2.   BEGIN
  3.   { For example. }
  4.     IF SELF.UseProc_A THEN
  5.       SELF.OnMouseDown := @SELF.HandleOnMouseDown_A
  6.     ELSE
  7.       SELF.OnMouseDown := @SELF.HandleOnMouseDown_B
  8.   END;
  9.  
Stupid question, sorry.

It would be worst if you don't ask. ;D
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

trayres

  • Jr. Member
  • **
  • Posts: 92
Re: How to change form callback dynamically?
« Reply #2 on: May 20, 2016, 06:43:02 pm »
Hi  Ñuño,

Thanks for the help, this will simplify my code dramatically :)

 

TinyPortal © 2005-2018