RAD Studio VCL Reference
|
property Enabled: Boolean;
__property Boolean Enabled;
Use Enabled to enable or disable the timer. If Enabled is true, the timer responds normally. If Enabled is false, the timer does not generate OnTimer events. The default is true.
C++ Examples:
/* This example uses a timer on a form. When the application runs and the user minimizes the application, the timer starts and the application returns to its normal size when an OnTimer event occurs. The timer then shuts down until the next time the form is minimized. Be sure to declare the AppStartTimer method as a public method of TForm1. Place a TTimer object in the form and enter Timer1Timer in the OnTimer event. */ void __fastcall TForm1::FormCreate(TObject *Sender) { Application->OnMinimize = AppStartTimer; Timer1->Interval = 1000; } void __fastcall TForm1::AppStartTimer(TObject *Sender) { Timer1->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Application->Restore(); Timer1->Enabled = false; }
/* This code ejects the CD from the CD-ROM player and shuts down the media player after 10 seconds. For the code to run correctly, you must have your CD audio device installed correctly, and the device must have software-ejecting capabilities. */ Word TimeOver; void __fastcall TForm1::FormClick(TObject *Sender) { MediaPlayer1->DeviceType = dtCDAudio; MediaPlayer1->Open(); MediaPlayer1->Play(); Timer1->Enabled = true; TimeOver = 0; } void __fastcall TForm1::Timer1Timer(TObject *Sender) { if (TimeOver == 10) { MediaPlayer1->Eject(); MediaPlayer1->Close(); // disable the timer, as we are done Timer1->Enabled = false; } else TimeOver++; }
Delphi Examples:
{ This example uses a timer on a form. When the application runs and the user minimizes the application, the timer starts and the application returns to its normal size when an OnTimer event occurs. The timer then shuts down until the next time the form is minimized. Be sure to declare the AppStartTimer method as a public method of TForm1. Place a TTimer object in the form and enter Timer1Timer in the OnTimer event. } procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMinimize := AppStartTimer; end; procedure TForm1.AppStartTimer(Sender: TObject); begin Timer1.Enabled := True; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Application.Restore; Timer1.Enabled := False; end;
{ This code ejects the CD from the CD-ROM player and shuts down the media player after 10 seconds. For the code to run correctly, you must have your CD audio device installed correctly, and the device must have software-ejecting capabilities. } var TimerOver: Word; procedure TForm1.FormClick(Sender: TObject); begin MediaPlayer1.DeviceType := dtCDAudio; MediaPlayer1.Open; MediaPlayer1.Play; end; procedure TForm1.Timer1Timer(Sender: TObject); begin if TimeOver = 10 then begin MediaPlayer1.Eject; MediaPlayer1.Close; { disable the timer, as we are done } Timer1.Enabled := False; end else if (MediaPlayer1.Mode = mpOpen) then Inc(TimeOver); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|