1 Востаннє редагувалося Chemist-i (26.11.2013 02:35:00)

Тема: Простий секундомір/Simple stopwatch (Delphi 7)

Найпростіший секундомірчик

код Delphi

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    XPManifest1: TXPManifest;
    Timer1: TTimer;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  t : int64;

implementation

{$R *.dfm}

function MsToStr(const msX : int64) : String;
  var day, h,m,s,ms : integer;
      s_day, s_h, s_m, s_s, s_ms : string;
begin
  day := ((msX div 1000) div 3600) div 24;
  h := ((msX div 1000) div 3600) - (day*24);
  m := ((msX div 1000) div 60) - (h * 60) - (day *24*60);
  s := (msX div 1000) - (m*60) - (h * 60 * 60) - (day * 24 * 60 * 60);
  ms := msX - (day * 24 * 60 * 60 * 1000) - (h*3600*1000) - (m*60*1000) - (s*1000);

  s_day := IntToStr(day);

  if h < 10 then
    s_h := '0'+IntToStr(h)
  else
    s_h := intToStr(h);

  if m < 10 then
    s_m := '0'+IntToStr(m)
  else
    s_m := intToStr(m);

  if s < 10 then
    s_s := '0'+IntToStr(s)
  else
    s_s := intToStr(s);

  if ms < 100 then
    if ms < 10 then
      s_ms := '00'+intToStr(ms)
    else
      s_ms := '0'+intToStr(ms)
  else
    s_ms := intToStr(ms);

  result := s_day + '_'+ s_h+':'+s_m+':'+s_s+'.'+ s_ms;

  {  for Q&A
  Form1.Memo1.Lines.Add('day='+IntToStr(day));
  Form1.Memo1.Lines.Add('h='+IntToStr(h));
  Form1.Memo1.Lines.Add('m='+IntToStr(m));
  Form1.Memo1.Lines.Add('s='+IntToStr(s));
  Form1.Memo1.Lines.Add('ms='+IntToStr(ms));
  }
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  t := GetTickCount;
  Timer1.Enabled := true;
  Button1.Caption := '1_Started...';
  Button1.Enabled := false;
  Button2.Enabled := true;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Lines.Add('Time='+  MsToStr(GetTickCount - t)+';');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Timer1.Enabled := false;
  Button1.Caption := '1_Start';
  Button1.Enabled := true;
  Button2.Enabled := false;
end;

procedure TForm1.Button4Click(Sender: TObject);
  const ins : array [0..7] of integer = (1000,1001,60000,60002,3600000,3600001,86400000,86400001);
  var   i : integer;
begin

  For i := 0 to 7 do
    begin
      Memo1.Lines.Add('------'+IntToStr(ins[i])+'------');
      Memo1.Lines.Add('------'+ MsToStr( ins[i] )+'------');
    end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption :=  MsToStr( (GetTickCount - t) );
end;

end.

Post's attachments

SecondMeter.zip 9.46 kb, 177 downloads since 2013-05-12 

x