Autor Beitrag
False Light
Hält's aus hier
Beiträge: 3



BeitragVerfasst: So 05.03.06 19:09 
hallo zusammen!

habe mir von einem bekannten ein timer erstellen lassen, der die zeit ab 00:00:00 zählen soll, wenn man auf "start" drückt. allerdings wird schon die zeit gezählt sobald das programm aufgerufen wird, das ganze wird nur nicht im label angezeigt. wenn ich dann z.b. nach 10 sekunden erst auf "start" drücke, beginnt der time nicht bei 00:00:00 sondern bereits bei :10, was er allerdings nicht soll ^^
das gleiche problem tritt dann auf, wenn ich die zeit mit "stop" einfrieren will. zwar steht dann die zeit im label still, im hintergrund wird aber trotzdem weitergezählt. nachdem mit "start" das ganze wieder fortgesetzt werden soll, landet der timer wieder ganz woanders.

tja und nun brauche ich eure hilfe; mein bekannten will ich nicht weiter damit belässigen, habe ihn schon genug gefragt und er hat derzeit anderes zutun.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
unit Stoppuhr;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, XPMan, ExtCtrls, Menus, INIFiles;

resourcestring
  rsTITLE = 'ServiceClock';

const
  suSOUND_DELAY = 100;    //ms

type
  TStoppuhrForm = class(TForm)
    Timer: TTimer;
    ZeitLabel: TLabel;
    startBB: TBitBtn;
    stopBB: TBitBtn;
    resetBB: TBitBtn;
    XPManifest: TXPManifest;
    MainMenu: TMainMenu;
    Info1: TMenuItem;
    About1: TMenuItem;
    procedure startBBClick(Sender: TObject);
    procedure stopBBClick(Sender: TObject);
    procedure TimerTimer(Sender: TObject);
    procedure resetBBClick(Sender: TObject);
    procedure About1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    Limit1  : Integer;
    Limit2  : Integer;
    StartTime : TDateTime;
    procedure ResetTimer;
  protected
  public
  published
  end;

var
  StoppuhrForm : TStoppuhrForm;
//                                     C   C#    D   D#    E    F    F#   G    G#   A    A#   H    C'   C#'  D'   D#'  E'   F'  F#'   G'  G#'   A'  A#'   H'  C''
  notes : array [0..24] of Integer = (261, 277, 294, 311, 330, 350, 371, 393, 417, 440, 466, 494, 524, 555, 589, 624, 660, 700, 742, 786, 833, 880, 933, 989, 1048);

implementation

uses DateUtils;

{$R *.dfm}

procedure TStoppuhrForm.ResetTimer;
begin
  StartTime         := Now;
  ZeitLabel.Caption := '00:00:00';
end;

procedure TStoppuhrForm.startBBClick(Sender: TObject);
begin
  //ResetTimer;
  Timer.Enabled   := True;
  stopBB.Enabled  := True;
  resetBB.Enabled := True;
  startBB.Enabled := False;
end;

procedure TStoppuhrForm.stopBBClick(Sender: TObject);
begin
  Timer.Enabled   := False;
  stopBB.Enabled  := False;
  //resetBB.Enabled := False;
  startBB.Enabled := True;
end;

procedure TStoppuhrForm.TimerTimer(Sender: TObject);
{
var
  Secs           : Integer;
  FormatSettings : TFormatSettings;
begin
  FormatSettings.LongTimeFormat := 'hh:mm:ss';

  ZeitLabel.Caption := TimeToStr(Now - StartTime);
  Caption           := rsTITLE + ' ' + ZeitLabel.Caption;
  Application.Title := Caption;

}

var
  Secs           : Integer;
  TimeDiff       : TDateTime;
  timeSECS, timeMIN, timeHOURS : string;
begin
  Secs     := SecondsBetween(Now, StartTime);
  TimeDiff := Now - StartTime;

  timeHOURS := IntToStr(HourOf(TimeDiff));
  if StrToInt(timeHOURS) < 10 then
    timeHOURS := '0' + timeHOURS;

  timeMIN := IntToStr(MinuteOf(TimeDiff));
  if StrToInt(timeMIN) < 10 then
    timeMIN := '0' + timeMIN;

  timeSECS := IntToStr(SecondOf(TimeDiff));
  if StrToInt(timeSECS) < 10 then
    timeSECS := '0' + timeSECS;

  ZeitLabel.Caption := timeHOURS + ':' + timeMIN + ':' + timeSECS;
  Caption           := rsTITLE + ' ' + ZeitLabel.Caption;
  Application.Title := Caption;





  if Secs < Limit1 then
    ZeitLabel.Font.Color := clBlack
  else
    if Secs < Limit2 then
      ZeitLabel.Font.Color := $00acff
    else
      ZeitLabel.Font.Color := clRed;
end;

procedure TStoppuhrForm.resetBBClick(Sender: TObject);
begin
  ResetTimer;
end;



schon mal vielen dank für die hilfe.

gruß
~FL
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 05.03.06 19:43 
Du solltest in 'startBBClick' nochmal 'ResetTimer' aufrufen.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
False Light Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: So 05.03.06 20:07 
ui, das ging ja schnell!

user profile iconuall@ogc hat folgendes geschrieben:
Du solltest in 'startBBClick' nochmal 'ResetTimer' aufrufen.


habe ich gemacht und es klappt auch soweit. allerdings wird nun der timer immer wieder auf null gesetzt wenn ich nach "stop" erneut auf "start" drücke. eigentlich soll es so sein das der zähler an der stelle weiter läuft, wo er zuletzt aufgehört hat. ansonsten wär' ja die "reset"-taste umsonst ^^
False Light Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mo 06.03.06 22:54 
hätte auch gerne noch eine progessbar im timer, die ab 4:20 min voll ist und möglicherweise die farbe ändert.
wie kann ich sowas noch zusätzlich einbauen?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 07.03.06 06:53 
Bitte pro Frage ein Thread. Damit hier kein durcheinander entsteht. Danke.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)