Example 5

Top  Previous  Next

 

Items

List of functions used for this example

In this example you will learn to

Protection schemes

Flowchart

Get the registration status

Default values of properties

Brief practice with the sample 5

 

 

List of functions used for this example:

This example is a compendium of all the functionalities of the component. It is a adaptation of the Demo1 of the old version 3.2. Below is a table with all methods used in this example:

 

Features

Description

Basic OLM


  OnlineGetKeyB()

Start the trial period or restore it

  OnlineCheckDate()

Check Online the local system date

Advanced OLM


  OnlineStartTrial()

Start the trial period or restore it

  OnlineExtendTrial()

Extend the trial period

  OnlineRegisterKey()

Register a given Registration Key

  OnlineRenew()

Only if (Paid=Y). Generates and applies a new registration key according with the online OLM data

  OnLineSynch()

Synchronize the local registration data from the OLM

  OnLineStartSecondary()

Secondary Registration: Generates a secondary record into the OLM and link it to a existing primary record

  OnLineMovePrimary1()

Move Primary Step1: Must be executed from the old computer. Deactivates the primary record and all linked secondaries

  OnLineMovePrimary2()

Move Primary Step2: Must be executed from the new computer. Reactivates the primary record and all linked secondaries

  OnLineRestorePrimary()

Undo the action performed by the Step1. Only possible before to apply the Step2

  OnLineMoveSecondary1()

Move Secondary Step1: Must be executed from the old computer. Deactivates the secondary record

  OnLineMoveSecondary2()

Move Secondary Step2: Must be executed from the new computer. Reactivates the secondary record

  OnLineRestoreSecondary()

Undo the action performed by the Step1. Only possible before to apply the Step2

  OnLineRemoveReg()

Remove the local registration data and the associated records from the OLM

  OnlineFullSynch()

Used to automate all basic steps namely; Start trial, Extend trial, Renew licence and Synchronize

Other


  GetModule()

Read the local registration data for the given module

  RegisterKey()

Register Key Offline (local registration only)

  MakeTrial()

Start locally the trial period based in the current system date. Not recommended

 

 

 

In this example you will learn to:

 

1. Save user data (Name, Company, and Email), locally on your

computer and in the OLM on your web server.

2. Manage primary and secondary licenses.

3. Moving licenses from one computer to another.

 

 

Protection schemes

This example implements the schemes D and F

 

 

              Scheme D

layout03

                    Scheme F

layout07

 

 

 

With this example we show most of the functionality offered by AVLock SIMPLE to implement all steps necessary throughout the lifecycle of your applications. Here we show all features, but you only need to use those more appropriate to your goal. With this example we pretend that you understand how the component works and the different methods and safety measures you can take to protect your application.

 

This example is implemented as shown in the following flowchart:

 

 

Flowchart

 

demo08a01

procedure TForm1.FormCreate(Sender: TObject);

begin

 DoRegister(False);

end;

 

procedure TForm1.DoRegister(force:boolean);

var F : TRegForm;

begin

 F:=TRegForm.Create(nil); //Create the registration Form

 try

   if force or (keydata.DaysLeft < 15) then F.ShowModal;

 finally

   FreeAndNil(F);

 end;

 if (keydata.Status = Registered)

 then begin

   BtnRestricted.Enabled := (IsValueOn(keydata.Values,1,0));

   BtnSpecial.Enabled := (IsValueOn(keydata.Values,1,1));

 end;

 lappname.caption:= AVLockS51.AppName;

 lusername.caption:= AVLockS51.UserName;

 lappversion.caption:= AVLockS51.AppVersion;

 lcompany.caption:= AVLockS51.Company;

end;

 

procedure TForm1.FormShow(Sender: TObject);

begin

 showabout(true);

end;

 

 

Get the registration status

 

The method GetRegStatus() into the Regist unit allow to get the current registration status of the component. Below you can see the source code. The first thing you do is assign the properties of the component, it has preset default settings (you can see them in a table below. It would only be necessary to assign values that do not match the preset, in our case only change the AppID value at we could have allocated only that property, too, for the most complete example is also assigned the remaining properties.

 

There we use the method GetKeyData() to read the local registration data and assign the 'keydata' record of TKeyData type. Then assigns the 'EdIcode' edit box with the Installcode value obtained from the machine, then in a case statement is prepared the message for the registration status to be shown in the top of the registration form and assigned to the caption of the lstatus label.

 

This method GetRegStatus, is called into the OnCreate event and at the end of each section of code that makes changes in the registration status, such as in BtnRegClick (), BtnRemoveClick (), BtnTrialClick () and BtnTrialOlmClick ().

 

 

procedure TRegForm.GetRegStatus;

var s, regdata:string;

   recordexists:boolean;

begin

 //Set properties

 with avlocks31 do begin

   EncryptionKey := 'abc123';

   AppID := 12341;  //default: 12345

   RemovableDisk := False;

   AppName := 'MyApp';

   AppVersion := '1.0.0';

   WebHost := 'www.av-soft.com';

   InstancesCtrl := False;

   RegPath := CommonDocuments;

   RegFolder := 'avlocks3d1';

   OlmPath := '/olm3';   //default: '/olm3'

   OlmBasicScript := 'basicolm.php';

   OlmAdvScript := 'advancedolm.php';

   V32Compat := False;

 end;

 AVLockS31.GetKeyData(0,keydata);

 EdIcode.Text := AVLockS31.InstallCode;

 EdName.Text := AVLockS31.UserName;

 EdCompany.Text := AVLockS31.Company;

 EdEmail.Text := AVLockS31.Email;

 s:='';

 case keydata.Status of

   Unregistered: s:='Not registered';

   Moved       : s:='Moved to another computer';

   Expired     : s:='Expired';

   Registered  : begin

     s:='Registered ';

     if keydata.Primary then s:=s+'as primary '

     else s:=s+'as secondary ';

     case keydata.KeyType of

       Trial     : s:=s+inttostr(keydata.Days)+' days trial - '+inttostr(keydata.DaysLeft)+' days left.';

       Temporal  : s:=s+inttostr(keydata.Days)+' days license - '+inttostr(keydata.DaysLeft)+' days left.';

       Permanent : s:=s+'(Permanent no time limit)';

     end;

   end;

 end;

 lstatus.caption:=s;

end;

 

 

KeyData is a record of type TKeyData declared in the component (unit AVLockS3.pas) as follow:

 

 TKeyData = 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;

 

 

Default value of properties

 

The component initialize its properties with the following values:

 

Properties

Default Values

Detail

EncryptionKey

'abc123'

Encryption key used for keys and other registration data.

EncryptionKey2

'xyz321'

Encryption key used to encrypt the data sent and received on the website.

AppID

12305

Application ID number.

RemovableDisk

False

Make True for portable applications.

AppName

'MyApp'

Application name.

AppVersion

'1.0.0'

Application version.

WebHost

'www.av-soft.com'

website url where you installed the OLM.

InstancesCtrl

False

If True it controls the number of instances executed simultaneously.

RegPath

CommonDocuments

Location within the local disk where is saved the registration data.

RegFolder

'avlocks3'

Name of the folder where is saved the registration data.

OlmPath

'/olm3'

Location within the hosting where you installed the OLM.

OlmBasicScript

'basicolm.php'

Name of the main script for the basic OLM.

OlmAdvScript

'advancedolm.php'

Name of the main script for the advanced OLM.

V32Compat

False

Compatibility with previous versions 3.x. Set it to true to update an existing application without their users have to register again. Installcode will remain the same as in the previous version.




 

Before using the component properties should be allocated according to their own settings. You only need to assign those who are different from those that are assigned by default, should at least assign different values for the following properties: EncryptionKey, EncryptionKey2 and AppID, and if you have installed the OLM into your own server also change the WebHost and OlmPath properties.

 

 

Brief practice with example 5

 

From the Delphi IDE open the example 5 (\Examples\5)

 

demo08a02

 

 

Run the application

Hit the runbutton button or click F9 to start the program.  In moments you will see the about box shown as a splash screen:

 

 

about01

 

 

This box is called from the OnShow event as you can see below:

 

showabout(True); //show the about box as splash screen

 

This function can be called with two different purposes 1) As a splash screen when the application starts (this case), or could be called  from a button within the application to see current registration status. See below the source code.

 

procedure TForm1.showabout(assplash:boolean);

var Ab : TFAbout;

begin

 Ab:=TFAbout.Create(nil);

 try

   Ab.LStatus.Caption := Status;

   Ab.LTooMany.Caption := TooMany;

   if reg0_ok then Ab.lreg.caption:='Registered to: '+lusername.Caption

   else Ab.lreg.caption:='';

   if assplash then Ab.tag:=0

   else Ab.tag:=1;

   Ab.showmodal;

 finally

   freeandnil(Ab);

 end;

end;

 

Quite simply, this only creates the form Ab, assigns the values of the labels LStatus, LTooMany and LRreg, then assigns the property tag (0 / 1) as the parameter assplash passed, then shows the form as modal and finally frees the Ab variable.

 

The following image shown as looks it at design time:

 

demo1about01

 

Wait a few seconds or press [Continue>>] to go to the main screen of the application.

 

demo1_03

 

Here we can see that two of the buttons are not enabled;

[Restricted Features] and [Special Features]. We use only one key to manage these two buttons through the Values field. For more information see the topic Registration Keys.

 

Let's click on the button [Show Registration Data] from the Registration Form, then see the following screen:

 

demo1_04

 

We see that the state is "Unregistered" Therefore, the absence of registration data the rest of the fields marked with "N/A".

 

Then close this screen and come back to the Registration form:

 

demo1_05

 

We see the registration status and below the "Install Code", a unique code for each computer based on the computer hardware.

 

If not already started the trial period, use the [Start Trial] button to start it.  Then you will see the changes in the Registration Status, also press the [Show registration Data] and see the changes made:

 

demo1_02

 

 

Come back to the main form and see how the buttons are enabled now:

 

demo1_01

 

With the [About Box] button we also could see the changes made in the registration status:

 

about02

 

We see that now there are registration data. Pressing the button [Start Trial] were made steps to create and register

a registration key of type trial in both the OLM (web page) as locally.

 

Below is the source code that is executed by pressing 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:=AVLockS51.OnlineStartTrial(0,1,1,30,'390');

 if (s='00') then begin

   showmessage('Trial started or registration synchronized');

   GetRegStatus;

 end else showmessage(Error2Str(s));

end;

 

For more information see the section How to start the trial.

 

The Trial period has started and the user has 30 days to test the application and decide the software acquisition.

 

The buttons [Contact us] and [Send email] allow the user to communicate with you to finalize the purchase transaction or any other sort of question he wants to do. The "Install Code" is automatically included in messages.

 

Once the user made the purchase and has sent you his "Install Code", you are able to calculate the registration key that enables the program in accordance with the agreement to purchase.

 

We may use either the RegMonitor or KeyGen utility to calculate the registration key we need. Let's try with KeyGen.

Suppose your user paid for a temporary registration (we use the key index 0) for a user and two instances.

 

keygen02

 

 

demo1_06a

 

Then we open the keygen.exe utility and enter the corresponding values: AppID, Version, Encryption Key, Module, Users, Instances and the InstallCode from the user's machine, select and assign Authorized Temporary days = 95. You can see the key generated in the Registration Key field. In a real case this key should be sent to the user, but as this is a test use it to register in Demo1, so copy and paste the key into the registration form, then hit the [Register Online] button and you will receive the following message:

 

demo1_08

 

Clicking again the [About Box] button, we see the changes made.

 

about03

 

From the Registration Form with the [Show Registration Data] button we see the new values:

 

demo1_06

 

 

The Demo1 source code

 

You have the source code of this example 5. It is well documented and what each function / procedure is quite obvious, however if something does not understand or need to be explained in more detail we want to please let us know.