Sample application

Top  Previous  Next

delphinet2For Delphi and .NET platforms

SAMPLE APPLICATION

 

app01

 

With AVLock SS we include sample applications for Delphi and .NET that will serve as a guide to deploy your application. This sample application simulates an accounting application with four modules: "General Ledger", "Account Receivable", "Account Payable" and "Stock / Inventory". Moreover, each of these modules are presented in three possible levels: Level1, Level2 and Level3. Below in the figure is the scheme of folders for the examples included in the package.

 

install_03

We have already shown how to implement four different versions of the application that we call "Editions" with the most common combinations of features. We prepare the editions Free, Entry, Standard and Professional. See into the topic "Using the Dev-Panel" the section Enter Product Editions.

 

Now we will see how to configure each application modules from the Dev-Panel.  In the "Editions" screen we have the string field "License Data". Below in the image we see the value that has been set for the edition "My Accounting Free".

 

editions_01

 

We will use the first 4 positions of the "License Data" field to control the modules as shown below:

 

editions_03

 

As we see, we take each of the first four digits in order to control modules. Here we considered sufficient to set values between 0 and 3 to determine the mode of operation of each module. In our practice we have defined each edition as shown in the following figure:

 

editions_02

 

The application code For Delphi

 

This sample app includes two main forms; MainUnit.pas, equivalent to the main form of your application and RegUnit.pas with licensing features. To implement this code in your application, copy RegForm.dfm and RegUnit.pas to your application folder then implement the functionality of MainUnit.pas in your own main form. Below is the files scheme for this example:

 

example_01

 

You must also add the following files to your application: avlockunit.dcu, rc_rndcrypts.dcu, rijndael_alg_refs.dcu, rijndael_api_refs.dcu. and conf.pas  Into the package are included compiled versions of these files for each Delphi version, from Delphi 5 to Delphi XE7.  You must copy the files that correspond to your version of Delphi.

 

In AVLock SS v2.x added the Licensor utility to generate license files to register computers that do not have internet and the sample application have also included this utility accessed from the "License Generator" button as we thought it might be useful to access this utility directly from the application. See more details on using this utility on the topic The Licensor.

 

These are the main forms included with this example:

 

example00b

 

example00c

 

MainUnit.pas with MainForm.dfm make the main form of the application. You. Must implement the code of this unit on the main form of your application. You must add the following code:

 

1. Add avlockunit to the uses clause.

2. Declare the variable AVLock: TAVLock;

3. Modify the conf.pas file with your own data.

 

//-----------------------------------------------------------------

// Pay close attention to complete this section with your own data.

// Very often make mistakes here.

// If you do not understand something please read the documentation

//-----------------------------------------------------------------

id_pro     := 1;  //Product-ID. Should match with the record ID

                //in the Dev-Panel See more info here.

Enc_Mode   := 1;  //0=weak encryption, 1=strong encryption

check_date := 1;  //check the system date when the app starts

mac_life   := 10; //Days of validity of the data read from the server

Web_Host   := 'www.<your-domain>';

Olm_Path   := '<olm-path>'; //In the example we entered /sspanel';

Olm_Script := 'olms.php';

Enc_Key    := 'xxxxxx'; //<enckey>

 

The conf.pas file is included into the initialization section of unit1.pas

 

initialization

 AVLock:=TAVLock.Create;

 with AVLock do begin

   {$I conf.pas}

 end;

 

finalization

 freeandnil(AVLock);

 

end.

 

 

Note that <enckey> should match with the value entered when you installed the User-Panel.

 

4. Add the DoRegister procedure declared as public

 

public

   { Public declarations }

   procedure DoRegister(force:boolean);

 

This is the implementation

 

procedure TForm1.DoRegister(force:boolean);

var F : TRegForm;

  ok:boolean;

begin

 AVLock.GetRegStatus;

 ok := (AVLock.reg_status in[2,3]);

 if not ok or force then begin

   F:=TRegForm.Create(self);

   try

   F.Showmodal;

   finally

     freeandnil(F);

   end;

 end;

 setmodules; //Optional

end;

 

5. Add this code into the OnCreate event.

 

procedure TForm1.FormCreate(Sender: TObject);

begin

 DoRegister(False);

 if not (AVLock.reg_status in [2,3]) then begin

   showmessage('The application is not active.');

   Application.Terminate;

 end;

 SetModules;

end;

 

This would be all you need to add in the case you not need to handle modules. As in our case we have modules, we will see how to handle it. For this purpose there is the LicData field (license data) which is a string with maximum length of 40 characters where you can define the settings for each product edition.  

 

In our example we used the first four characters of the LicData field to define modules, one character per module. If 0 or blank module is not active, if you take the values ​​from 1 to 3 is active and the number represents the level of the module.

 

Let's look at the code that we have implemented:

 

6. Declare two arrays to handle the modules:

 

   modules1 : array[1..4] of char;

   modules2 : array[1..4] of string;

 

7. Defines the SetModules procedure

 

Declare it in the Public section and define it as follows:

 

procedure TForm1.setmodules;

var i,l:integer;

begin

 //Initialize modules

 for i:=1 to 4 do modules1[i] := '0';

 for i:=1 to 4 do modules2[i] := 'Inactive';

 

 //Set Modules

 if (AVLock.reg_status in [2,3]) then begin

   l:= length(AVLock.lic_data);

   if (l>4) then l:= 4;

   for i:= 1 to l do begin

     modules1[i] := AVLock.lic_data[i];

     if (modules1[i] = '0') then modules2[i] := 'Inactive'

     else modules2[i] := 'Active. Level '+modules1[i];

   end;

 end;

 

 btnmod1.Enabled := (modules1[1] <> '0');

 btnmod2.Enabled := (modules1[2] <> '0');

 btnmod3.Enabled := (modules1[3] <> '0');

 btnmod4.Enabled := (modules1[4] <> '0');

 

 lstat1.Caption := modules2[1];

 lstat2.Caption := modules2[2];

 lstat3.Caption := modules2[3];

 lstat4.Caption := modules2[4];

end;

 

 

8. In the onclick event of each button a message is displayed, but you should put code here to access the proper module.

 

 

9. Compile the la application then execute it:

 

The first thing that appears is the registration form. Here the user must place the email address and password with which you registered on your site AVLock SS. I did tests with my email address as you can see in the image below:

 

example01

 

By clicking on the "Register Now" button, if the data is correct is passed directly to the main form of the application:

 

example02

 

By clicking on the "Registration Form" button we come back to the registration form, now only shows status information, registration period and attached machines.

 

example03

 

This state corresponds to the Standard edition just registered. See Subscribing for the Standard Edition.

 

The registration on a given machine can be turned off in order to activate it on another machine. This can be very useful in the case of having a single machine such as the Dev-Panel Free. Let's try to disable the application with the "Disable this machine" button. After click it is shown the following message on screen:

 

example04

 

The application has been disabled on this machine as you can see now on the registration form. With the "Continue >>" button, it displays the message "The application is not active" and the app is closed.

 

example05

 

Now we can activate the application on another machine. Assuming you already have the application installed on PC2, then run the app and register it. We see that the only thing that changes is the Mac-Code, which is the code that identifies the machine and is different for each:

 

example06

 

Let's do some more tests. From the Dev-Panel modify the subscription and uncheck the "Lockable" box, as seen in the image below:

 

example07

 

 

Open the application again and see the result:

 

example08

 

Now try checking the "Disabled" box.

 

example09

 

This is the result:

 

example10

 

Try to reactivate the machine with the button "Enable this machine". We obtain the following result:

 

example11

 

We see that the subscription has been deactivated and therefore also all machines attached to the subscription.

 

We have also included in the example an additional feature that allows the user to access to the News page of your site directly from the application. This feature is implemented with the files wbrowser.pas and WebForm.dfm.

 

example_02

 

 

The application code For .NET c#

 

The implementation for the example and the Licensor utility in Visual Studio 13 is very similar to that made in Delphi. In this case the configuration data for the example is in the MainForm.cs file and for the  Licensor utility in the Form1.cs file. The lines that you must change are at the beginning of each file (lines 16-23) and are as follows:

 

//---------CONFIGURATION SECTION---------------

public static uint ID_PRO = 1;

public static uint CHECK_DATE = 0; //0=no chek, 1=check

public static string OLM_URL = "http://yourdomain.com/sspanel/olms.php";

public static string ENC_KEY = "xxxxxx"; //should match with $enckey in conf.php

//LOCAL_PATH is Where the *.avr file will be saved. Change it if you preffer another location

public static string LOCAL_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

//---------------------------------------------