W jaki sposób z synchronizować Timer z zegarem systemowym z dokładnością do 100ms chodzi mi o to żeby zdarzenie wykonywało się o konkretnych godzinach np. w taki sposób:
00:00:01'0000
00:00:01'0100
00:00:01'0200
00:00:01'0300
00:00:01'0400

//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <mmsystem.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTimer *Timer1;
TLabel *Label1;
TButton *StartButton;
TButton *ResetButton;
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall StartButtonClick(TObject *Sender);
void __fastcall ResetButtonClick(TObject *Sender);
private: // User declarations
long startTime, elapsedTime;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
startTime = 0;
elapsedTime = 0;
Label1->Caption = "0.000";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
elapsedTime = timeGetTime() - startTime;
Label1->Caption = FloatToStrF( ((float)elapsedTime) / 1000.0, ffNumber, 7, 3);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StartButtonClick(TObject *Sender)
{
if(Timer1->Enabled)
{
Timer1->Enabled = false;
StartButton->Caption = "Start";
}
else
{
startTime = timeGetTime();
elapsedTime = 0;
Timer1->Enabled = true;
StartButton->Caption = "Stop";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ResetButtonClick(TObject *Sender)
{
startTime = timeGetTime();
elapsedTime = 0;
Label1->Caption = "0.000";
}
//---------------------------------------------------------------------------

Powrót do Ogólne problemy z programowaniem
Użytkownicy przeglądający ten dział: Brak zalogowanych użytkowników i 2 gości