Main.pas 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. unit Main;
  2. interface
  3. uses
  4. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  5. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
  6. type
  7. TMainForm = class(TForm)
  8. btnChrono: TButton;
  9. lblElapsedTime: TLabel;
  10. lblElapsedTimeLong: TLabel;
  11. tiChrono: TTimer;
  12. Label3: TLabel;
  13. lblTimer: TLabel;
  14. lblShortFormat: TLabel;
  15. lblLongFormat: TLabel;
  16. cbPrecissionFormat: TComboBox;
  17. Label1: TLabel;
  18. procedure btnChronoClick(Sender: TObject);
  19. procedure FormCreate(Sender: TObject);
  20. procedure tiChronoTimer(Sender: TObject);
  21. private
  22. { Private declarations }
  23. public
  24. { Public declarations }
  25. end;
  26. var
  27. MainForm: TMainForm;
  28. StartDate : TDateTime;
  29. implementation
  30. uses
  31. Quick.Chrono;
  32. var
  33. crono : TChronometer;
  34. hola : string;
  35. {$R *.dfm}
  36. procedure TMainForm.btnChronoClick(Sender: TObject);
  37. begin
  38. if btnChrono.Caption = 'Start' then
  39. begin
  40. crono.ReportFormatPrecission := TPrecissionFormat(cbPrecissionFormat.ItemIndex);
  41. StartDate := Now();
  42. tiChrono.Enabled := True;
  43. crono.Start;
  44. btnChrono.Caption := 'Stop';
  45. end
  46. else
  47. begin
  48. crono.Stop;
  49. tiChrono.Enabled := False;
  50. btnChrono.Caption := 'Start';
  51. lblElapsedTime.Caption := crono.ElapsedTime;
  52. lblElapsedTimeLong.Caption := crono.ElapsedTime(True);
  53. end;
  54. end;
  55. procedure TMainForm.FormCreate(Sender: TObject);
  56. begin
  57. crono := TChronometer.Create(False);
  58. end;
  59. procedure TMainForm.tiChronoTimer(Sender: TObject);
  60. var
  61. newtime : string;
  62. begin
  63. tiChrono.Enabled := False;
  64. try
  65. newtime := FormatDateTime('hh:mm:ss',Now()-StartDate);
  66. if newtime <> lblTimer.Caption then lblTimer.Caption := newtime;
  67. finally
  68. tiChrono.Enabled := True;
  69. end;
  70. end;
  71. end.