unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, ExtCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
// FormCreate ist die Lösung
private
{ Private declarations }
Zielzeit: TTime;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ini: TIniFile;
filename:
String;
begin
filename := ExtractFilePath(ParamStr(0)) + '
zeit.ini';
ini := TIniFile.Create(filename);
Zielzeit := now + 1;
try
ini.WriteTime('
Daten','
Zielzeit',Zielzeit);
finally
ini.Free;
end;
Timer1.Enabled:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption:= TimeToStr(zielzeit - now);
if now >= Zielzeit
then
begin
Timer1.enabled:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
// FormCreate verwenden
var
ini: TIniFile;
filename:
String;
begin
filename := ExtractFilePath(ParamStr(0)) + '
zeit.ini';
ini := TIniFile.Create(filename);
try
if ini.ReadDateTime('
Daten','
Zielzeit',Zielzeit) < now
then
begin
timer1.Enabled:=true;
end;
finally
ini.Free;
end;
end;
end.