Example 5 |
Top Previous Next |
Items List of functions used for this example In this example you will learn to 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:
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
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:
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:
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)
Run the application Hit the button or click F9 to start the program. In moments you will see the about box shown as a splash screen:
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:
Wait a few seconds or press [Continue>>] to go to the main screen of the application.
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:
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:
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:
Come back to the main form and see how the buttons are enabled now:
With the [About Box] button we also could see the changes made in the registration status:
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.
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:
Clicking again the [About Box] button, we see the changes made.
From the Registration Form with the [Show Registration Data] button we see the new values:
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.
|