【列表5.12】Sleeper程序代码。
{
frmSleeper - Demonstrate the sleep() library function
}
unit frmSleeper;
interface
uses
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs,
QExtCtrls, QStdCtrls, Libc;
type
TSleeperMainForm = class(TForm)
ExitBtn: TButton;
StartBtn: TButton;
SleepMemo: TMemo;
TimerMemo: TMemo;
Timer: TTimer;
procedure SleepySye;
procedure ExitBtnClick(Sender: TObject);
procedure StartBtnClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
SleeperMainForm: TSleeperMainForm;
implementation
{SR *.xfm}
procedure TSleeperMainForm. SleePyBye;
var
i : Integer;
s : String;
begin
Timer. Enabled := True;
SleepMemo.Clear;
TimerMemo.Clear;
s := 'Start... ';
SleepMemo,Text :=s;
for i :=1 to 4 do
begin
Application.ProcessMessages;
__Sleep(5);
s := s + IntToStr(i * 5);
if i then s := s + '... '
else s := s + '!';
SleepMemo.Text := s;
end; { for }
end;
procedure TSleeperMainForm. ExitBtnClick(Sender: TObject);
begin
Close;
end;
procedure TSleeperMainForm. StartBtnClick(Sender: TObject);
begin
SleepyBye;
end;
procedure TSleeperMainForm.TimerTimer(Sender: TObject);
begin
Timer. Enabled := False;
TimerMemo.Text := 'The 12-second timer has fired!';
end;
end.