unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,ShellAPI;
//須用到ShellAPI
type
TForm1 = class(TForm)
Timer1: TTimer;
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Started:Boolean;
rectime:TDateTime;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Started:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Started:=True;
rectime:=now; //記錄當前時間
Timer1.Enabled:=True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
IF Started=True then
IF now>rectime+StrToDateTime(Edit1.Text) then
ExitWindowsEx(EWX_SHUTDOWN,0);
//ExitWindowsEx請參考Delphi Help中的Windows SDK
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=False;
started:=False;
end;
end.
這個是最簡單最簡單的啦﹐希望能起到拋磚引玉的作用﹐看個人自己發揮啦。