
|
Before to use AVLock Simple with your software it is convenient to do a brief practice with the demo applications included in the package. There are four sample applications. Demo4 is the more elemental implementation using only the Basic OLM and Demo1 is a compendium of all features in the component. Please review below the comparison chart.
|
Features
|
Demo1
|
Demo2
|
Demo3
|
Demo4
|
Description
|
Basic OLM
|
|
|
|
|
|
OnlineGetKeyB()
|
Yes
|
|
|
Yes
|
Start the trial period or restore it
|
OnlineCheckDate()
|
Yes
|
Yes
|
Yes
|
Yes
|
Check Online the local system date
|
Advanced OLM
|
|
|
|
|
|
OnlineStartTrial()
|
Yes
|
Yes
|
Yes
|
|
Start the trial period or restore it
|
OnlineExtendTrial()
|
Yes
|
Yes
|
Yes
|
|
Extend the trial period
|
OnlineRegisterKey()
|
Yes
|
Yes
|
Yes
|
|
Register a given Registration Key
|
OnlineRenew()
|
Yes
|
Yes
|
Yes
|
|
Only if (Paid=Y). Generates and applies a new registration key according with the online OLM data
|
OnLineSynch()
|
Yes
|
|
|
|
Synchronize the local registration data from the OLM
|
OnLineStartSecondary()
|
Yes
|
|
Yes
|
|
Secondary Registration: Generates a secondary record into the OLM and link it to a existing primary record
|
OnLineMovePrimary1()
|
Yes
|
Yes
|
Yes
|
|
Move Primary Step1: Must be executed from the old computer. Deactivates the primary record and all linked secondaries
|
OnLineMovePrimary2()
|
Yes
|
Yes
|
Yes
|
|
Move Primary Step2: Must be executed from the new computer. Reactivates the primary record and all linked secondaries
|
OnLineRestorePrimary()
|
Yes
|
Yes
|
Yes
|
|
Undo the action performed by the Step1. Only possible before to apply the Step2
|
OnLineMoveSecondary1()
|
Yes
|
|
Yes
|
|
Move Secondary Step1: Must be executed from the old computer. Deactivates the secondary record
|
OnLineMoveSecondary2()
|
Yes
|
|
Yes
|
|
Move Secondary Step2: Must be executed from the new computer. Reactivates the secondary record
|
OnLineRestoreSecondary()
|
Yes
|
|
Yes
|
|
Undo the action performed by the Step1. Only possible before to apply the Step2
|
OnLineRemoveReg()
|
Yes
|
|
|
|
Remove the local registration data and the associated records from the OLM
|
OnlineFullSynch()
|
Yes
|
Yes
|
Yes
|
|
Used to automate all basic steps namely; Start trial, Extend trial, Renew licence and Synchronize
|
Other
|
|
|
|
|
|
GetModule()
|
Yes
|
Yes
|
Yes
|
Yes
|
Read the local registration data for the given module
|
RegisterKey()
|
Yes
|
Yes
|
Yes
|
Yes
|
Register Key Offline (local registration only)
|
MakeTrial()
|
Yes
|
|
|
|
Start locally the trial period based in the current system date. Not recommended
|
Modules used
|
0
|
0
|
0,1,2
|
0
|
Each module have their own key and record into the OLM.
|
Features controlled
|
3
|
3
|
3
|
2
|
Buttons and others characteristics controlled by the modules
|
DEMO1
With the Demo1 sample we illustrate the majority of the features included with the new AVLock Simple v3.x. However, probably you will not need to implement all these features into your application, use only those that you consider appropriate to your software.
Open the Demo1 into your Delphi IDE (I'm using Delphi 7 for practices) and select the AVLockS3 component to see its properties into the Object Inspector. Note that the WebHost property have the URL for the site from where the component will access to perform the online licensing procedure. In order to test the component you can use the default value "www.valega.com" but when you implement your own application then use the URL from your web site.

Open the source code for the project file Project1.dpr from (Project > View source)
program Project1;
uses
Forms,
unit1 in 'unit1.pas' {Form1},
Regist in 'Regist.pas' {RegForm},
About in 'About.pas' {FAbout},
regstatus in 'regstatus.pas' {RegStatusForm};
{$R *.res}
var s:string;
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
with Form1 do begin
avlocks31.EncryptionKey := 'abc123';
avlocks31.EncryptionKey2 := 'xyz321';
avlocks31.AppID := 12341;
Automatize; //Start Trial, Extend trial or Renewal automatically
showabout(True); //show the about box as splash screen
end;
Application.Run;
end.
IMPORTANT: You should change the values for EncryptionKey and AppID before to test this demo in order to ensure that your demo has its own separate record in the web site data.
When it runs, first will be executed the three lines changing the EncryptionKey, EncryptionKey2 and AppID. Then the following optional lines:
Automatize; //Start Trial, Extend trial or Renewal automatically
showabout(True); //show the about box as splash screen
Both, Automatize() and showabout are in the unit1.pas file, please take a look to this unit:
TForm1 = class(TForm)
...
public
{ Public declarations }
Module: TModuleData;
procedure GetModule;
procedure showabout(assplash:boolean);
procedure showregdata;
Procedure Automatize;
procedure DoRegister;
end;
procedure TForm1.GetModule;
begin
AVLockS31.GetModule(0,Module);
if AVLockS31.DateWarning or AVLockS31.DateBacked then begin
if not AVLockS31.OnlineCheckDate
then begin
showmessage('Your system date seems to be incorrect. Please review it, '+
'check your internet connection and try again.');
application.Terminate;
end;
end;
end;
Procedure TForm1.Automatize;
var s: string;
begin
GetModule;
if (module.Status = Registered) and (module.KeyType = Permanent) then exit;
s:=AVLockS31.OnlineFullSynch(0);
s:=AVLockS31.OlmError2Str(s);
if (s<>'') then showmessage(s);
end;
The TModuleData type is declared in the component (unit AVLockS3.pas) as follow:
TModuleData = record
Status : TRegStatus;
KeyType : TKeyType;
Startdate : TDate;
EndDate : TDate;
Days : word;
DaysLeft : word;
Users : byte;
Instances : byte;
Primary : boolean;
DateBacked : boolean;
TooManyInstances : boolean;
Values : string;
Key : string;
//For secondary registrations
ICodeP : string;
InstallCodep : string;
end;
Now you would be ready to understand how this work, when Automatize is called this executes GetModule in order to read the local data into the Module record, then the following line exit the operation for Permanent Registered users, this will avoid an unnecessary delay for registered users.
if (module.Status = Registered) and (module.KeyType = Permanent) then exit;
Then if the user isn't a Permanent Registered user the following line is executed:
s:=AVLockS31.OnlineFullSynch(0);
This line calls the OLM using the advancedkeymanager.php script which first search into the web server database the record where the module number is equal to 0 (the passed parameter) and the Installcode is equal to the current installcode (AVLocks31.InstallCode) retrieved from the computer. If the record exists this will be read and returned to the component else a new trial primary record will be added into the database and returned to the component. Then the local registration data will be sinchronized using the data returned from the server database.
If the operation fail a error message will be displayed through the following two lines:
s:=AVLockS31.OlmError2Str(s);
if (s<>'') then showmessage(s);
The following line into the dpr file is:
showabout(True); //show the about box as splash screen
This function could be called with two different purposes 1) As a splash screen when the application starts (this case) and to be called from a button to show the current registration status. See its look in the image below:

The showabout() function is into the unit1.pas file, take a look to its code.
procedure TForm1.showabout(assplash:boolean);
var Ab : TFAbout;
begin
GetModule;
Ab:=TFAbout.Create(nil);
try
if assplash then Ab.tag:=0
else Ab.tag:=1;
Ab.showmodal;
finally
Ab.free;
end;
end;
Very simple, this only creates the Ab form, set the tag property (0/1) according with the assplash parameter, then shows the form at modal way and finally free the Ab variable. So all things are made into the about.pas unit, see part of the code below:
var
time0 : ttime;
waittime : single;
ok : boolean;
implementation
uses unit1;
{$R *.DFM}
procedure TFAbout.GradBut2Click(Sender: TObject);
begin
close;
end;
procedure TFAbout.FormShow(Sender: TObject);
var i,n:integer;
begin
with Form1 do
Begin
GetModule;
LTooMany.Visible := Module.TooManyInstances;
LStatus.Caption := AVLockS31.Status2Str(Module);
if (LStatus.Caption = 'Registered')
then LReg.Caption := 'Registered to '+avlocks31.UserName
else LReg.Caption :='';
end;
if (Tag=0) then waittime:=0.00005 //called as splashScreen
else waittime:=0.0005; //called as about box
time0:=time+waittime;
end;
procedure TFAbout.Timer1Timer(Sender: TObject);
begin
if (time>time0) then modalresult:=mrOk;
end;
procedure TFAbout.BtnCloseClick(Sender: TObject);
begin
modalresult:=mrOk;
end;
procedure TFAbout.Image1Click(Sender: TObject);
begin
modalresult:=mrOk;
end;
end.
Below is the form as look at design status:

The code from the FormShow() procedure is called, then GetModule is executed to renew the fields into the Module record.
Then the following lines are called in order to set the controls into the form:
LTooMany.Visible := Module.TooManyInstances;
LStatus.Caption := AVLockS31.Status2Str(Module);
if (LStatus.Caption = 'Registered')
then LReg.Caption := 'Registered to '+avlocks31.UserName
else LReg.Caption :='';
The following lines sets the waittime variable depending of the tag property, more short time for splash screen than for about box:
if (Tag=0) then waittime:=0.00005 //called as splashScreen
else waittime:=0.0005; //called as about box
time0:=time+waittime;
The form is closed at two different ways:
1) if the user clicks on the [Continue >>] button.
2) when the defined waittime is consumed. See the Timer1Timer() procedure.
So, waiting some seconds or pressing the [Continue >>] button we go on the main program screen.

There are two disabled butons, [Restricted Features] and [Special Features]. Unlike the previous version 2.x where we use two modules 0 and 1 in order to control these features, now we use only the module 0 and control these features through the Values field. For more information see the THE MODULES section into the "How AVLock SIMPLE works".
Click on the [Show Registration Data] button, then the following window will be displayed:

Note the "Unregistered" status meaning no registration data found. So, all other fields are marked as "N/A".
Press the [Registration] button then you will see the following screen (the registration form):

There is a welcome message on the top of the form and below the "Install Code", an unique value calculated from the hardware.
If the trial period is not started yet then you can start it from the [Start Trial] button. Try it and see how now both buttons are enable into the main form.

With the [About Box] button you can see the changes happened:

With the [Show Registration Data] see the registration data again. Now there are the registration data for the module started as trial. when you pressed the [Start Trial] button. The registration data was created either, into the local disk and for the OLM into your web site.

Below is the source code from the Demo1 for the [Start Trial] button:
procedure TRegForm.BtnTrialOlmClick(Sender: TObject);
var s:string;
begin
if not testfields(False) then exit;
//assign username and company values to properties before register
writeData;
//Start Trial from the OLM
s:=Form1.AVLockS31.OnlineStartTrial(0);
if (s='00') then showmessage('Trial started or registration synchronized')
else showmessage(Form1.AVLockS31.OlmError2Str(s));
end;
For more information see the How to Start Trial section into the "How AVLock SIMPLE works" topic.
Click again the [Registration] button and note that the new welcome message changed according with the actual situation (trial started). The trial period has been started and the user have 30 days to try the application and decide to buy your product.

The [Contact us] and [Send email] buttons allows to the user to communicate with you in order to decide the purchase operation or receive any other question from your user. The "Install Code" is automatically included into the messages.
Once the user purchased your application and you have the Install Code coming from his machine, you are in situation to calculate the registration key to habilitate the program according with the purchase.
We can use either; the KeyGen or the RegMonitor utilities in order to calculate the key but we will try first with the KeyGen utility.
Suppose that your user paid for a temporary registration (we use the module 0) for one user and two instances.

Open the KeyGen.exe utility and enter the proper values for AppID, Version, Encryption Key, Module, users and instances, then enter the Installcode, select Temporary and set Authorized days to 95. The key will be calcuated and available in the Registration Key field.
For a real life case you send it to the user, but for this sample we will register the key into the Demo1. So, copy and paste the key from the KeyGen to the Registration Form as in the next image:

Press the [Register] button, then if all happened successfully you will get the following message:

Click again the [About Box] button and see the changes made:

With the [Show Registration Data] see the new Registration Data:

See other practices made with this Demo1 in the following sections:
1) How AVLock SIMPLE Works > HOW TO START THE TRIAL PERIOD
2) How AVLock SIMPLE Works > HOW TO EXTEND THE TRIAL PERIOD
3) How AVLock SIMPLE Works > HOW TO REGISTER THE APPLICATION USING A REGISTRATION KEY
4) How AVLock SIMPLE Works > HOW TO REGISTER THE APPLICATION USING THE OLM
The sourced for Demo1
You have the sources of the Demo1 and it is quite documented, however, if you do not understand some thing please let us know.
DEMO 2
This sample intend to reproduce a real life application. We use the same demo1 scheme but now using only the needed features.
The PageControl used only shows the appropriate features according with the current registration status, for the Unregistered status (see the image below) only are visible two tabs; "Start Trial" and "Advanced"

|
allowing to the user:
1) To start the trial period: Normally the user will use this option in order to start the trial period.
2) To reactivate a moved registration: This is the step 2 into the process to move a license from a computer to another. So this will be the new computer where the existing registration will be retaken in order to continue using it. See the image below.

|
Click the [StartTrial] button, then a 30 days trial period will be started. The next time that you open the Registration Form this will look like the next image:

|
Now, while the Trial Status, only will be visible the "Registration" tabsheet, the "StartTrial" and "Advanced" tabsheets are hidden since this options are not available for the Trial Status. In this tabsheet you have three options:
1) Registration using a Registration Key: After purchase the user receive the registration key to register the application.
2) Registration from the OLM: After purchase you modify the proper record into the OLM and set (Paid=Y). Then the user will be able to register the application with the [Activate] button. This option may be removed if you use the Automatize procedure (see the sources).
3) Synchronize: If for any reason the local registration data becomes corrupt, the user can restore it from the OLM with this option. This option may be removed if you use the Automatize procedure (see the sources).
When the user start the trial period and when he register the application, will be prompted to enter his personal data. This should match with the real actual values. So, if for any reason there are incorrect values or has changed its email address, he can re enter the correct values and saves it with the [Save user data] button.
|
Register the application (temporal or permanent) using any of the two available methods (See the demo1 sample above). Then, the next time you open the registration form this will look like the next image:

|
Now, while the application is registered with a temporal or permanent registration, two tabsheets will be available. "Registration" and "Advanced".

|
For more information about these functions please see the Demo1 Sample above.
DEMO3
This sample is another approach to implement a real life application. In the previous samples we did use only one module in order to manage all options into the application but now for this demo we are using three modules, namely:
0: To manage the whole application
1: To manage additional features 1
2: To manage additional features 2
The program is blocked while the unregistered or expired status for the module 0. Let us open the source code for the project from (Project > View source):
program project1;
uses
Forms,
Main in 'main.pas' {MainForm},
Reg in 'Reg.pas' {RegForm},
About in 'About.pas' {FAbout},
RegStatus in 'regstatus.pas' {RegStatusForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
with MainForm do
Begin
avlocks31.EncryptionKey := 'abc123';
avlocks31.EncryptionKey2 := 'xyz321';
avlocks31.AppID := 12343;
Automatize; //Start Trial, Extend trial or Renewal automatically
showabout(True); //show the about box as splash screen
//show the Registration Form only while the trial period (False)
DoRegister(False);
end;
Application.Run;
end.
Note the line: DoRegister(False). This line is added here since in this sample the application need to be blocked when the module 0 is in unregistered or expired status, and allowed when the status is Registered. The blocking is done just in this form disabling the [Continue >>] button.

|
When we run the application the About Box show the registration status, initially all unregistered. After some seconds or pressing the [Continue >>] button we go on the registration form.

|
With this form we can manage all steps of the licensing cycle.

|
First we select the module from the drop down list then at the right side under the "Module status" title is the status for the selected module.
|

|
Next we select the action to apply to the selected module. The available options on the drop down list depends of the current registration status for the selected module.
So, for the Unregistered status there are 4 options, namely: Start Trial Online, Register as Secondary, Register Key Offline and Reactivate from Moved Registration (primary).
|
This is the complete list of possible actions:
0. Start Trial Online
1. Register as Secondary
2. Register Key Offline
3. Activate Online
4. Register Key Online
5. Extend Trial Online
6. Move Registration to another computer
7. Restore (Undo Move Operation)
8. Reactivate from Moved Registration (primary)
9. Reactivate from Moved Registration (secondary)
For more information about these actions please see the Demo1 Sample above.
DEMO4
This sample is another approach to implement a real life application. In this case the more elemental implementation using only the Basic OLM.
There are only two units unit1.pas, the main form, and Regist.pas the registration form. All features are controlled with only one module. In the main form are four buttons: [Registration] in order to show the registration, [Main Features] controlled with the module status. [Additional 1] and [Additional 2] controlled by the Values field.

|
[Main Features] controlled with the module status.
[Additional1] controlled by the Values field.
[Additional2] controlled with the Values field.

|
The project file is very simple, see it below:
program Project1;
uses
Forms,
Unit1 in 'unit1.pas' {Form1},
Regist in 'Regist.pas' {RegForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
with Form1 do begin
avlocks31.EncryptionKey := 'abc123';
avlocks31.AppID := 12344;
DoRegister(False);
end;
Application.Run;
end.
Note the line: DoRegister(False). This line is added here since in this sample the application need to be blocked when the module 0 is in unregistered or expired status, and allowed when the status is Registered. The blocking is done just in this form disabling the [Continue >>] button.

The source code for the DoRegister() procedure is below:
procedure TForm1.DoRegister(force:boolean); //force = show anyway
var F: TRegForm;
s,res: string;
err,
daysbefore: byte; //days before to warning
showform : boolean; //form must be displayed
begin
avlocks31.GetModule(0,module); //Read the module from the local registration data
//****Check System Date using the OLM****
if AVLockS31.DateWarning or AVLockS31.DateBacked then begin
if not AVLockS31.OnlineCheckDate
then begin
showmessage('Your system date seems to be incorrect. Please review it, '+
'check your internet connection and try again.');
application.Terminate; //Terminate the application when the system date is incorrect
end;
end;
//****Online trial generation from the basic OLM****
if (module.Status = Unregistered) then
begin
res := Form1.AVLockS31.OnlineGetKeyB('300',0,0,30,1);
if (res='00') //No error, Read again the registration status for the module 0
then avlocks31.GetModule(0,module);
end;
daysbefore := 15; //Days before expiration from where you want to show
//this registration form
//showform is set to true when the module status is in Unregistered, Expired or Moved,
//or when the Key Type is Trial or Temporal and daysbefore is reached.
showform := (module.Status in [Unregistered, Expired, Moved])
or (module.KeyType in [Trial, Temporal]) and (module.daysleft < daysbefore);
if showform or force then
begin
F:=TRegForm.Create(nil); //Create the registration Form
try
//Set labels to show modules status
F.LMain.Caption := AVLockS31.Status2Str(Module);
if AVLockS31.IsValueOn(module.Values,1,0)
then F.Ladd1.Caption := 'Enabled'
else F.Ladd1.Caption := 'Disabled';
if AVLockS31.IsValueOn(module.Values,1,1)
then F.Ladd2.Caption := 'Enabled'
else F.Ladd2.Caption := 'Disabled';
//set values to show on the form
F.EdIcode.Text:= avlocks31.InstallCode;
F.ShowModal; //show the form
if (F.ModalResult = mrYes) then begin //[Register] button pressed
err:=avlocks31.RegisterKey(F.EdKey.Text); //try to register the key
//this method doesn't need that you enter the module number since internally the
//key have this number. In this case the key must be prepared for the module 0
case err of //possible results after try to register the key
0: s:='Your Key has been Registered';
1: s:='Error: Key length mismatch';
2: s:='Error: Bad system date';
3: s:='Your Key has been UnRegistered';
4: s:='Error: Invalid Registration Key';
else s:='Unknown error';
end;
showmessage(s); //show the registration result
avlocks31.GetModule(0,module); //Read again the registration status for the module 0
end else if not force and (F.ModalResult = mrCancel) then Application.Terminate;
finally
F.Free;
end;
end;
BtnMain.enabled := (module.Status = Registered);
if BtnMain.enabled then begin
BtnAdd1.enabled := AVLockS31.IsValueOn(module.Values,1,0);
BtnAdd2.enabled := AVLockS31.IsValueOn(module.Values,1,1);
end else begin
BtnAdd1.enabled := False;
BtnAdd2.enabled := False;
end;
end;
I tried to make this help file clear, readable and complete, this is my goal, but it is possible that I leave behind some important things that you were expecting. So, if you miss something or have found bugs or have some idea to improve this help, please let me know.
|
Alcides Valega
Author of AVLock SIMPLE
|
|