Registriert seit: 20. Jun 2004
155 Beiträge
Delphi 5 Standard
|
Re: Betriebsstundenzähler
4. Okt 2006, 19:15
Hier mein schnell gebastelter Betriebsstundezähler:
- Label1: seit
- Label2: ... Mal gestartet
- Label3: Betriebsstunden
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var save: TIniFile;
begin
startTime := now;
save := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\save.ini');
Label1.Caption := save.ReadString('Save', 'Since', DateTimeToStr(now));
Label2.Caption := IntToStr(save.ReadInteger('Save', 'Runs', 1));
timeOffset := save.ReadDateTime('Save', 'Time', 0);
save.Free;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if not Shutdown then
begin
if MessageDlg('Wollen Sie das Programm wirklich beenden ?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then
begin
CanClose := False;
Exit;
end;
end;
end;
//[edit]
procedure TForm1.WMENDSESSION(var Msg: TWMQueryEndSession);
var save: TIniFile;
begin
save := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\save.ini');
save.WriteString('Save', 'Since', Label1.Caption);
save.WriteInteger('Save', 'Runs',StrToInt(Label2.Caption)+1);
save.WriteDateTime('Save', 'Time', timeOffset + now-startTime);
save.Free;
//[edit]
Msg.Result := 1;
Shutdown := True;
// inherited;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
save: TIniFile;
begin
save := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\save.ini');
save.WriteString('Save', 'Since', Label1.Caption);
save.WriteInteger('Save', 'Runs',StrToInt(Label2.Caption)+1);
save.WriteDateTime('Save', 'Time', timeOffset + now-startTime);
save.Free;
end;
function convertTime(time: Extended; dms: String): Integer;
begin
if dms='d' then result:= Floor(time)
else if dms='h' then result:= Floor( (time-Floor(time))*24 )
else if dms='m' then result:= Floor( (time*24-Floor(time*24))*60 )
else if dms='s' then result:= Floor( (time*24*60-Floor(time*24*60))*60 )
else result:=-1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.Caption := IntToStr(convertTime(timeOffset + now-startTime, 'd')) + ' d' + #13#10
+ IntToStr(convertTime(timeOffset + now-startTime, 'h')) + ' h' + #13#10
+ IntToStr(convertTime(timeOffset + now-startTime, 'm')) + ' m' + #13#10
+ IntToStr(convertTime(timeOffset + now-startTime, 's')) + ' s' + #13#10;
end;
|
|
Zitat
|