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;
function GetIniFilename:
string;
function ReadZeitwert: TDateTime;
procedure WriteZeitwert(Zeit: TDateTime);
public
{ Public declarations }
property IniFilename:
string read GetIniFilename;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
SECTION = '
Daten';
IDENT = '
Zielzeit';
function TForm1.GetIniFilename:
string;
begin
Result := ExtractFilePath(ParamStr(0)) + '
zeit.ini';
end;
function TForm1.ReadZeitwert: TDateTime;
var
ini: TIniFile;
begin
ini := TIniFile.Create(IniFilename);
try
Result := ini.ReadDateTime(SECTION, IDENT, 0);
finally
ini.Free;
end;
end;
procedure TForm1.WriteZeitwert(Zeit: TDateTime);
var
ini: TIniFile;
begin
ini := TIniFile.Create(IniFilename);
try
ini.WriteDateTime(SECTION, IDENT, Zeit);
finally
ini.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Zielzeit := now + 1;
WriteZeitwert(Zielzeit);
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
begin
Zielzeit := ReadZeitwert;
Timer1.Enabled := Zielzeit > now;
end;
end.