Note: This is not the complete source code--just the main source file.
You can download the full source (with include files) from our
sample code archive by clicking on the diskette icons.
unit HexGadgetsLic;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, HexValidEmailLib, HexDnsLib, HexTcpQueryLib, HexLookupLib,
HexIcmpLib, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
Label20: TLabel;
lblHicmpLicense: TLabel;
Label19: TLabel;
lblHicmpError: TLabel;
Label21: TLabel;
memoHicmpKey: TMemo;
memoHveKey: TMemo;
Label3: TLabel;
Label2: TLabel;
lblHveLicense: TLabel;
Label1: TLabel;
lblHveError: TLabel;
Label4: TLabel;
lblHdnsLicense: TLabel;
Label6: TLabel;
lblHdnsError: TLabel;
Label8: TLabel;
memoHdnsKey: TMemo;
Label9: TLabel;
lblHtcpqLicense: TLabel;
Label11: TLabel;
lblHtcpqError: TLabel;
Label13: TLabel;
memoHtcpqKey: TMemo;
Label14: TLabel;
lblHlkupLicense: TLabel;
Label16: TLabel;
lblHlkupError: TLabel;
Label18: TLabel;
memoHlkupKey: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetLicenseErrorString( error: Integer ) : String;
begin
case error of
0: Result := 'Success';
2: Result := 'License file not found';
3: Result := 'Could not open license file';
4: Result := 'License file is corrupt';
5: Result := 'License is for wrong product';
6: Result := 'License is for wrong version';
7: Result := 'License does not cover all processors in the machine';
else
Result := Format( 'Other error: %d', [error] );
end;
end;
function GetLicenseTypeString( licensedProcs: Integer; error: Integer ) : String;
begin
if (licensedProcs > 0) then
Result := Format( '%d-processor', [licensedProcs] )
else if ( licensedProcs = -1 ) then
Result := 'Site'
else if ( licensedProcs = -2 ) then
Result := 'Enterprise'
else if ( error <> 0 ) then
Result := 'None'
else
Result := 'Runtime';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Terminate();
end;
procedure TForm1.FormCreate(Sender: TObject);
var
hve : HexValidEmailLib.IConnectionSync;
hdns : HexDnsLib.IConnectionSync;
htcpq : HexTcpQueryLib.IHexTcpQuerySync;
hlkup : HexLookupLib.IHexLookupSync;
hicmp : HexIcmpLib.IHexIcmpSync;
begin
{
When you're creating your Delphi application using HexGadgets for COM...
1. Add the relevant .PAS file to your project. For example, if you're using
HexValidEmail, add HexValidEmail.pas.
2. Add ComLicensing.pas to your project.
3. Add the relevant Unit name to the uses clause of your code. Add
HexValidEmailLib to use HexValidEmail, for instance.
4. Use the CreateLicensed function to create an instance as shown below.
Initially you can use any string as a license key. The evaluation period
will remain in force. You can use the Expires property to find out when
the eval period ends.
After you've purchased a license...
1. Put the license file in the same directory as the currently registered
HexGadget DLL. For example, put HexValidEmail.lic in the same directory
as HexValidEmail.dll.
2. Run your application (or this sample application) and use the GetLicenseKey
function to retrieve the runtime license key string. You only need to do
this once, and your license file must be installed correctly for this to
work.
3. Store the license key string in your application and pass it to the
CreateLicensed function when you call it. When you have a valid runtime
license key, the Error and LicensedProcessors properties will both be 0
immediately after you call CreateLicensed.
4. Now you can distribute your application. Because the HexGadget is using
your embedded runtime key, your application will work without your license
file.
}
// HexValidEmail license information
// We have to specify HexValidEmailLib here because both HexValidEmail
// and HexDns have Connection classes. If you're just using one or the other,
// you don't have to specify the unit name.
hve := HexValidEmailLib.CoConnection.CreateLicensed( 'Put your key here' );
lblHveError.Caption := GetLicenseErrorString( hve.Error );
lblHveLicense.Caption := GetLicenseTypeString( hve.LicensedProcessors, hve.Error );
memoHveKey.Text := HexValidEmailLib.CoConnection.GetLicenseKey();
// HexDns license information
hdns := HexDnsLib.CoConnection.CreateLicensed( 'Put your key here' );
lblHdnsError.Caption := GetLicenseErrorString( hdns.Error );
lblHdnsLicense.Caption := GetLicenseTypeString( hdns.LicensedProcessors, hdns.Error );
memoHdnsKey.Text := HexDnsLib.CoConnection.GetLicenseKey();
// HexTcpQuery license information
htcpq := CoHexTcpQuery.CreateLicensed( 'Put your key here' );
lblHtcpqError.Caption := GetLicenseErrorString( htcpq.Error );
lblHtcpqLicense.Caption := GetLicenseTypeString( htcpq.LicensedProcessors, htcpq.Error );
memoHtcpqKey.Text := CoHexTcpQuery.GetLicenseKey();
// HexLookupLib license information
hlkup := CoHexLookup.CreateLicensed( 'Put your key here' );
lblHlkupError.Caption := GetLicenseErrorString( hlkup.Error );
lblHlkupLicense.Caption := GetLicenseTypeString( hlkup.LicensedProcessors, hlkup.Error );
memoHlkupKey.Text := CoHexLookup.GetLicenseKey();
// HexIcmpLib license information
hicmp := CoHexIcmp.CreateLicensed( 'Put your key here' );
lblHicmpError.Caption := GetLicenseErrorString( hicmp.Error );
lblHicmpLicense.Caption := GetLicenseTypeString( hicmp.LicensedProcessors, hicmp.Error );
memoHicmpKey.Text := CoHexIcmp.GetLicenseKey();
end;
end.