Examples Delphi

Subject: RE: Trial versions
Raigo,
Check out CyberBolt:
http://www.mindspring.com/~efd/CyberBlt.htm
I've never used it, but that's what it's for (time-limited demos, etc.)
Steve Helgeson
Lamplighter Software
-----Original Message-----
From: owner-delphi@Kyler.com [mailto:owner-delphi@Kyler.com]On Behalf Of
Lukk Raigo
Sent: Monday, March 22, 1999 2:49 PM
To: Delphi@Kyler.com
Subject: Trial versions
Hi
The company I work for wants to create trial versions of some of
our Delphi applications.
I have seen these kind of trial Delphi applications.
But how to do it?
Has any of you done it?
We agreed that best would leave the application as it is, and give it
some limitation of time like 60 days or whatever.
I have had quite many trial CDs most of them work for limited time
and after the time passes they won't run. Reinstalling wont put it to
work. Setting back calendar won't work. So nothing seems to work.
I would appreciate any kind of feedback of doing something like
this.
Thanks
From: Richard Ebbs
To: Lukk Raigo
Subject: Trial versions
Hi Lukk
In response to your query:
> How to do it? (Delphi Trial versions)...
I recently played with coding a time-limitation into
a program. So these ideas are more or less my own...
what I did was to get the current date (from within the
program installation routine) and then ENCRYPT the current
date, and write it to file as a 'psuedo' .DLL file in
the Windows directory. Then each time the actual program
is run more or less the first thing it does is to
UNENCRYPT the date in that file, compare it against 'now'
and if the difference is greater than 'install_date plus
30' then terminate the program and inform the user...
I'll leave the string encryption to you (could be a simple
'shifting' of ASCII codes, or could involve XORing, which
may be better...)
so, in your installation program you need to get the Windows
directory:
const
SFName = 'youNameIt.dll';
trialLen = 30;
trialLenStr = '30 day';
function TInstallForm.GetWindowsDir: String;
{here we use a call to the Windows API function GetWindowsDirectory() to find
out the FULL PATH NAME (including the drive) of the Windows directory...}
const
{not really used but we COULD check that the directory
name is less than 100 characters in length...}
maxDirNameLen = 100;
var
dirName: array[0..maxDirNameLen] of char;
begin
GetWindowsDirectory(dirName, sizeof(dirName));
Result := String(dirName);
end;
then hand the result of proc above to a procedure
something like this:
procedure TInstallForm.WriteToDLL(longWinName: String);
var
SF: TextFile;
currDate, instDate, outFileName: String;
fileOpenOK: Boolean;
begin
fileOpenOK := True;
outFileName := longWinName + '\' + SFName;
AssignFile(SF, outFileName);
try {to open destination file}
reWrite(SF);
try
{get the current date, in String format...}
currDate := DateToStr(Date);
{the encryption up to you}
currDate := EnCrypt(currDate);
{write the inst date to file...}
WriteLn(SF, currDate);
finally
closefile(SF);
end;
except
on E: EInOutError do
begin
MessageDlg('Error reading or writing startup file:' + #13 +
GetError(E.ErrorCode)+'.', mterror,[mbOK], 0);
end
end; {trying to open destination file}
end;
note that we don't check for the pre-existence of the fake
.DLL file (although it might be useful to do that...)
so now you've got an encrypted installation date on disc,
the next thing is to include IN YOUR ACTUAL PROGRAM a routine
to read that encrypted date, unencrypt it, and do the
comparison: something like this:
procedure TEditorForm.ReadFromDLL;
const
dirNameLen = 100;
var
winDirName, troutName, dateStr, tempString: String;
dirName: array[0..dirNameLen] of Char;
troutFile: TextFile;
today, dayOfInst, dateDiff: TDateTime;
pastSellByDate: Boolean;
{year, month, day: Word;}
begin
pastSellByDate := False;
GetWindowsDirectory(dirName, dirNameLen);
winDirName := String(dirName);
troutName := winDirName + '\youNameIt.dll';
AssignFile(troutFile, troutName);
try {to open source file}
reSet(troutFile);
try
ReadLn(troutFile, dateStr);
finally
closefile(troutFile)
end; {putting source file data into memory}
except
on E: EInOutError do
begin
tempString := 'Could not open required initialisation file. Aborting Program';
Application.MessageBox(PChar(tempString), ' Missing Startup File', mb_OK);
end
end; {trying to open source file}
today := Date;
{leave the UNencryption to you}
dateStr := UnEncrypt(dateStr);
dayOfInst := StrToDate(dateStr);
dateDiff := (today - dayOfInst);
if (dateDiff > trialLen) then pastSellByDate := True;
if (pastSellByDate = True) then
begin
tempString := 'Your ' + trialLenStr + ' trial period has expired. Sorry!';
Application.MessageBox(PChar(tempString), ' Past Expiry Date', mb_OK);
Application.Terminate;
end;
end;
PS if you're worried about anyone 'hacking' your application
such that they amend or remove routines like this it may be
a good idea to do the opposite of what I was taught at college
ie -give all of these routines/variables etc totally obscure
names so that a hacker can't easily home in on a string that
says 'UnEncrypt()' or whatever...
Hope this is useful
Richard Ebbs