如何实倒数计时,(100分)

  • 主题发起人 主题发起人 柳枫
  • 开始时间 开始时间

柳枫

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,一个考试程序,考试时间为一个小时,以一秒一秒倒数计时,
直至结束,如何实现,请指教,谢谢!
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
beginTime: TDateTime;
endTime: TDateTime;
public
procedure beginTest;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.beginTest;
begin
beginTime := Now;
endTime := IncHour(beginTime, 1);
Timer1.Interval := 200;
Timer1.Enabled := true;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
beginTest;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
s: string;
i: integer;
time_now: TDateTime;
begin
time_now := now;

s := FormatDateTime('hh:nn:ss', endTime - time_now);
Label1.Caption := s;

i := SecondsBetween(time_now, endTime);
Label2.Caption := Format('剩余 %d 秒', );

end;

end.
 
后退
顶部