delphitimettimer

How can I create a `onClick` event for the timer in the events section?


The program I am using has a small section for programming which is almost similar to the Delphi programming language.

In the components section, there is no timer and I want to create it myself.

{$FORM TForm2, Unit2.sfm}                                

uses
  Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
  var
  Timer : TTimer ;

procedure Form2Create(Sender: TObject);
begin
  Timer := TTimer.create(Application);  
  Timer.Enabled := True ;
  Timer.Interval := 1000 ;                                 
  Timer.OnTimer := true ;                             
  Timer.Name := 'Watch';
  Timer.Free ;
end;

How can I create a onClick for the timer in the events section? enter image description here

The program I am using is Ensign 10.


Solution

  • The TTimer component doesn't have a onClick event. You need to give it an onTimer event.

    I don't know exactly how it works in your program, but in Delphi it'll work like this. You create the event like so:

    procedure TForm2.TimerTick(Sender: TObject);
    begin
      ShowMessage('Timer ticked!');
    end;
    

    And then you can assign it to the timer like this when creating the timer:

    Timer.OnTimer := TimerTick;
    

    Then TimerTick will be called for every interval.


    Edit: There's ESPL Manual: Ensign Software Programming Language specifically for your software "Ensign 10".

    I don't see anything related to a timer in the manual, but if it has the TTimer, then according to the manual, I think you'd need to use it like this:

    {$FORM TForm2, Unit2.sfm}                                
    
    uses
      Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
    
    var    // correct indention, just like "uses" and "procedure"
      Timer: TTimer;
    
    procedure TimerTick;
    begin
      ShowMessage('Timer ticked!');
    end;
    
    procedure Form2Create(Sender: TObject);
    begin
      Timer := TTimer.create(Application);  
      Timer.Interval := 1000;        // first set the interval...
      Timer.OnTimer := 'TimerTick';  // ...and its event...
      Timer.Enabled := True;         // ...then activate the timer after everything's set up
      Timer.Name := 'Watch';
    end;