不好意思,雞婆一下~~ 照醬子看來,gemi0305應該是用BCB6, 所以你們的 RTL不一樣,
其實你只要照著code 再做一個就好了啊,你可用記事本打開他專案中的
標頭檔(counter.h) , 及打開他的實作檔(counter.cpp)
就可看到所有內容了, 然後 執行他的執行檔,就可知道他用了哪些元件,
然後自己實作一個,才會加深映像啊!! 他的標頭檔及實作檔如下:
//------底下是標頭檔------------------------------------------------------------- #ifndef counterH
#define counterH
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp>
#include
//---------------------------------------------------------------------------
counter.h
#define Min 0
#define Sec 1
#define Msec 2
#define Mmsec 3
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
TButton *Button3;
TLabel *Label1;
TTimer *Timer1;
TBevel *Bevel1;
TBevel *Bevel2;
TLabel *Label2;
TLabel *Label3;
TButton *Button4;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
private: // User declarations
int t;
unsigned char TimeClass;
TDateTime start; public: // User declarations
AnsiString toTime(int iTime, unsigned char TimeClass);
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif //*************底下是實作部分 ****************************************** //--------------------------------------------------------------------------- #include
#pragma hdrstop #include "counter.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
start=Now();
}
//--------------------------------------------------------------------------- AnsiString TForm1::toTime(int iTime, unsigned char TimeClass)
{
int h=0,m=0,s=0,ms=0; //秒、分、時
AnsiString TempStr; switch(TimeClass)
{
case Min: //以分為單位
h=m/60; //取時
m=iTime%60; //取分 TempStr.printf("d:d",h,m); //設定格式為00:00
break; case Sec: //以秒為單位
m=iTime/60; h=m/60; //取時
m=m%60; //取分
s=iTime%60; //取秒 TempStr.printf("d:d:d",h,m,s); //設定格式為00:00:00
break; case Msec: //以1/10秒為單位
s = iTime/10;
m = s/60; h =m/60;
m = m%60;
s = s%60; ms=iTime; //取1/10秒 TempStr.printf("d:d:d:%d",h,m,s,ms); //設定格式為00:00:00:0
break; case Mmsec: //以1/100秒為單位
s = iTime/100;
m = s/60; h =m/60;
m = m%60;
s = s%60; ms=iTime0; //取1/10秒
TempStr.printf("d:d:d:%2d",h,m,s,ms); //設定格式為00:00:00:00
default:
break;
} return(TempStr); }
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
/*Tdatatime用的-----------------------------------------------*/
switch(TimeClass)
{
case Min:
Label2->Caption=(Now()-start).FormatString("hh:nn");
break; case Sec:
Label2->Caption=(Now()-start).FormatString("hh:nn:ss");
break; default:
break;
} /*function用的----------------------------------------------- */
t++;
Label1->Caption = toTime(t, TimeClass); }
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled=false;
Label1->Caption="00:00"; //usefunction
t=0; Label2->Caption="00:00"; //useDateTime
start=Now();
Timer1->Enabled=true;
Timer1->Interval=60000; //以分為單位
TimeClass = Min; } //---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false; Label1->Caption="00:00:00"; //usefunction
t=0; Label2->Caption="00:00:00"; //useDateTime
start=Now(); Timer1->Enabled=true;
Timer1->Interval=1000; //以秒為單位
TimeClass = Sec; }
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Timer1->Enabled=false; Label1->Caption="00:00:00:0"; //usefunction
t=0; Label2->Caption="無法顯示 "; //useDateTime Timer1->Enabled=true;
Timer1->Interval=100; //以1/10秒為單位
TimeClass = Msec;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Timer1->Enabled=false; Label1->Caption="00:00:00:0"; //usefunction
t=0; Label2->Caption="無法顯示 "; //useDateTime Timer1->Enabled=true;
Timer1->Interval=10; //以1/100秒為單位
TimeClass = Mmsec;
}
//---------------------------------------------------------------------------
你也可以直接用站上的'線上發簡訊給我'
的功能' 發給 吉米零三零五(gemi0305),http://delphi.ktop.com.tw/pop_profile.asp?mode=display&id=10756 問他些一些細節...
===三人行必有我師焉===