Birkaç gündür uğraştığım bir projem var ancak bir türlü çözüm bulamadım. Bir adet kronometre yapmaya çalışıyorum. Lap tuşuna basıldığında stringgride veri aktaracak. Timer ile yaptım interval 1000 de saniye olarak sıkıntı çıkmıyor ama interval degerini ne yaparsam yapayım sağlam sonuç elde edemedim. İnternette şöyle bir örnek buldum bunu uyarlayamadım nasıl yapabilirim yardımcı olabilir misiniz?
Kod: Tümünü seç
unit Main;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls, Inifiles, SavePos,
StopwatchComp, LCD_Lab;
type
TMainForm = class(TForm)
SavePos1: TSavePos;
ButtonPanel: TPanel;
StartButton: TButton;
ResetButton: TButton;
OptionsButton: TButton;
StopwatchLabel: TStopwatch;
LapButton: TButton;
procedure StartButtonClick(Sender: TObject);
procedure ResetButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OptionsButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure LapButtonClick(Sender: TObject);
private
{ Private declarations }
procedure SetSegmentSize (Value : integer);
function GetSegmentSize : integer;
procedure EnableButtons;
procedure ResizeForm;
protected
procedure WndProc(var Message: TMessage); override;
public
{ Public declarations }
property SegmentSize : integer read GetSegmentSize write SetSegmentSize;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
uses
Options, Math;
const
CRegKey = 'Software\Doogal Software\Stopwatch\Properties';
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.SetSegmentSize (Value : integer);
begin
case Value of
2 : StopWatchLabel.PixelSize := pix2x2;
3 : StopWatchLabel.PixelSize := pix4x4;
4 : StopWatchLabel.PixelSize := pix6x6;
end;
ResizeForm;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.ResizeForm;
begin
ClientHeight := StopWatchLabel.Height + ButtonPanel.Height;
ClientWidth := Max (StopWatchLabel.Width, OptionsButton.Left + OptionsButton.Width + 4);
end;
////////////////////////////////////////////////////////////////////////////////
function TMainForm.GetSegmentSize : integer;
begin
case StopWatchLabel.PixelSize of
pix2x2 : Result := 2;
pix4x4 : Result := 3;
pix6x6 : Result := 4;
else
Assert(False);
Result := 2;
end;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.StartButtonClick(Sender: TObject);
begin
if StopWatchLabel.Suspended then
StartButton.Caption := '&Stop'
else
StartButton.Caption := '&Start';
StopWatchLabel.Suspended := not StopWatchLabel.Suspended;
EnableButtons;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.EnableButtons;
begin
ResetButton.Enabled := StopWatchLabel.Suspended;
LapButton.Enabled := not StopWatchLabel.Suspended;
end;
{******************************************************************************}
procedure TMainForm.ResetButtonClick(Sender: TObject);
begin
StopWatchLabel.Reset;
end;
{******************************************************************************}
procedure TMainForm.FormCreate(Sender: TObject);
begin
// get stuff from the registry
StopWatchLabel.LoadFromRegistry(CRegKey);
ResizeForm;
// setup the title and things
Application.Title := 'Stopwatch';
StopWatchLabel.Caption := ResetString;
EnableButtons;
end;
{******************************************************************************}
procedure TMainForm.OptionsButtonClick(Sender: TObject);
begin
with OptionsForm do
begin
// set up old values
OldUpdateSpeed := StopWatchLabel.UpdateSpeed;
OldLitColour := StopWatchLabel.PixelOn;
OldUnLitColour := StopWatchLabel.PixelOff;
OldBackColour := StopWatchLabel.BackGround;
OldSize := SegmentSize;
// set up new values
UpdateSpeed := StopWatchLabel.UpdateSpeed;
btnLit.ButtonColour := StopWatchLabel.PixelOn;
btnUnLit.ButtonColour := StopWatchLabel.PixelOff;
btnBack.ButtonColour := StopWatchLabel.BackGround;
Size := SegmentSize;
Show;
end;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.FormDestroy(Sender: TObject);
begin
StopWatchLabel.SaveToRegistry(CRegKey);
end;
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.WndProc(var Message: TMessage);
begin
inherited WndProc(Message);
if Message.Msg = WM_ACTIVATEAPP then
begin
if TWMActivateApp(Message).Active then
begin
Application.Title := 'Stopwatch';
end;
end;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.LapButtonClick(Sender: TObject);
begin
StopwatchLabel.Lapping := not StopwatchLabel.Lapping;
end;
end.