Board index » delphi » Creating a new TTimer

Creating a new TTimer

Hello!!!

I want to create a new Timer and add some variables to it,
for example i, j.
Can this be done without create a new component?

Thanks

 

Re:Creating a new TTimer


If you want to create a timer from 'thin air' - here is an example -
on the other hand maybe what you want to do is 'utilize' an existing
timer for several tasks - one method is to put something in the
existing Timer's Tag

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    Procedure OnMyTimer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  MyTimer: TTimer;

implementation

{$R *.DFM}

Procedure TForm1.OnMyTimer(Sender: TObject);
Begin
    TTimer( Sender ).Enabled := False ;
    ShowMessage( 'TICK !' ) ;
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyTimer := TTimer.Create( Self );
  MyTimer.OnTimer := OnMyTimer ;
  MyTimer.Interval := 100 ;
  MyTimer.Enabled := True ;
end;

end.

On 27 Jul 2001 07:15:42 -0700, mkei...@starmedia.com (Marco Keiler)
wrote:

Quote
>Hello!!!

>I want to create a new Timer and add some variables to it,
>for example i, j.
>Can this be done without create a new component?

>Thanks

Other Threads