Dynamically create a message window and display a progress bar in the window. Select a button within the progress bar.
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, extctrls, stdctrls, comctrls;
Type
Tform1 = Class (tform)
Button1: tbutton;
Procedure button1click (Sender: tobject );
Procedure dialogtimer (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
VaR
Amsgdialog: tform;
Aprogressbar: tprogressbar;
Atimer: ttimer;
Begin
Amsgdialog: = createmessagedialog ('Quickly! Answer yes or no! ', Mtwarning, [mbyes, mbno]);
Aprogressbar: = tprogressbar. Create (amsgdialog );
Atimer: = ttimer. Create (amsgdialog );
With amsgdialog do
Try
Tag: = 10; // seconds!
Caption: = 'you have 10 seconds ';
Height: = 150;
With aprogressbar do begin
Name: = 'progress ';
Parent: = amsgdialog;
MAX: = amsgdialog. Tag; // seconds
Step: = 1;
Top: = 95;
Left: = 8;
Width: = amsgdialog. clientwidth-16;
End;
With atimer do
Begin
Interval: = 1000;
Ontimer: = dialogtimer;
End;
Case showmodal
Id_yes: showmessage ('answered "yes ".');
Id_no: showmessage ('answered "no ".');
Id_cancel: showmessage ('time up! ')
End; // case
Finally
Atimer. ontimer: = nil;
Free;
End;
End;
Procedure tform1.dialogtimer (Sender: tobject );
VaR
APB: tprogressbar;
Begin
If not (sender is ttimer) Then exit;
If (sender as ttimer). Owner) is tform then
With (sender as ttimer). Owner) as tform do
Begin
APB: = tprogressbar (findcomponent ('progress '));
If APB. Position> = APB. Max then
Modalresult: = mrno
Else
APB. stepit;
End;
End;
End.