Failed to Create a Demo


2005-07-15 08:26:17 PM
cppbuilder31
After taking at look at the example form Remy's post
.... I still puzzled that why I CANNOT set a proper First Installation
date by goign through the registry at all ...
My Expriation Date setting Code canbe shown as follows:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
...
TDateTime dtNow = Now();
TDateTime dtFirstRun;
TDateTime dtExpired;
TDateTime dtCountDown;
int Period = 15;
TRegistry *Reg = new TRegistry;
Reg->RootKey = HKEY_CURRENT_USER;
if( Reg->OpenKeyReadOnly("\\SOFTWARE\\Cephxxxx\\1.0\\") )
{
if( Reg->ValueExists("First Run") )
{
dtFirstRun = Reg->ReadDateTime("First Run");
dtExpired = dtFirstRun+Period;
}
Reg->CloseKey();
}
if( dtFirstRun == (TDateTime)0 )
{
if( Reg->OpenKey("\\SOFTWARE\\Cephxxxx\\1.0\\", true))
{
Reg->WriteDateTime("First Run", dtNow);
Reg->CloseKey();
dtExpired = dtFirstRun+Period;
Application->MessageBox(("This trial will expire on "
+DateTimeToStr(dtExpired)).c_str(), "First Run!", MB_OK);
}
}
else if( dtExpired>= dtNow )
{
Application->MessageBox("This trial has expired.",
"EXPIRED!",MB_OK);
Application->ShowMainForm = false;
Application->Terminate();
}
else if( dtExpired <= dtNow )
{
// CountDown
dtCountDown = dtExpired - dtNow;
Application->MessageBox(("There are
"+DateTimeToStr(dtCountDown)+"Days Left before
Expiration").c_str(),MB_OK);
}
delete Reg;
}
I just leave a BLANK space in string "First Run" within the registry
directory HKEY_CURRENT_USER\SOFTWARE\CephSmile\1.0\
to allow me to write the date data from function Now() into
the registry ....
I just WONDER how could I write the First Instllation data of my
program's registry .....