Outsource Code / Using Timer without a Form

In order to make scripter programs more clear I want to outsource some portions of my code to special units.
For example I have build some helper functions and saved them in "srcWindowFunctions".
In my scripting form I write uses srcWindowFunctions. Then I can use these procedures and functions.
This is working "reasonably satisfactory".

Now I tried to outsource a Timer. Instead of putting the TTimer on my Scripting Form I defined the Timer inside srcWindowFunctions.

var
  WinSizeAndPosTimer : TTimer;

...
  if WinSizeAndPosTimer = null then begin
    WinSizeAndPosTimer := TTimer.Create(Self);
    WinSizeAndPosTimer.OnTimer := WinSizeAndPosTimerTimer(Self, Sender);
    WinSizeAndPosTimer.Interval := 1000;
    WinSizeAndPosTimer.Enabled := true;
  end;
  // Manual Call of Timer Event:
  WinSizeAndPosTimerTimer(Self, Sender); // Fensterposition nach dem Öffnen sofort wieder herstellen

Unfortunately the Timer gives me every second the message RUNTIME ERROR File library srcWindowFunctions: Subroutine '0' does not exist in script Position: 0, 0.
But the first "manual" call direct after creation works perfect.

How can I solve that problem?

That's not how you set an event handler in scripter. The correct way is to pass the function name:

    WinSizeAndPosTimer.OnTimer := 'WinSizeAndPosTimerTimer';

Thank you. This was the solution.
Now it works perfectly. :ok_hand:

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.