home *** CD-ROM | disk | FTP | other *** search
- program SlsDemo;
-
- uses
- Windows,
- Forms,
- Dialogs,
- Buttons,
- SysUtils,
- Controls,
- MainForm in 'MainForm.pas' {FormMain},
- SlsApi in 'SlsApi.pas',
- About in 'About.pas' {AboutBox},
- CSheriff in 'CSheriff.pas',
- RegisterFrm in 'RegisterFrm.pas' {RegisterForm},
- LicenceFrm in 'LicenceFrm.pas' {LicenceForm};
-
- {$R *.RES}
-
- const
- szProductID: array[0..32] of Char = '9758-3050-1918-9292-6466'#0;
- szProductName: array[0..32] of Char = 'Sheriff Demo Delphi'#0;
- szLicencePath: array[0..32] of Char = 'c:\temp'#0;
- szUserName: array[0..32] of Char = 'Trial'#0;
- g_arySecrets:TSecrets =
- (
- ($76,$3E,$6D,$36,$14,$14,$6D,$B8,$1D,$CA,$F3,$D5,$34,$2D,$08,$BC,$14,$31),
- ($00,$B7,$17,$00,$43,$FC,$C0,$7F,$8F,$A2,$22,$D2,$1B,$62,$B3,$DE,$95,$3F),
- ($AC,$2E,$39,$6F,$45,$D5,$41,$11,$43,$41,$2B,$75,$9C,$B2,$67,$6E,$14,$02),
- ($79,$52,$9A,$49,$97,$8B,$1C,$15,$64,$B7,$BE,$6C,$7F,$18,$C3,$4E,$78,$87)
- );
-
- var
- Sheriff:TSheriff;
- vRelease:SLS_RELEASE;
-
- procedure ShowSheriffError;
- var strError:string;
- begin
- Sheriff.GetLastErrorMessage(strError);
- MessageBox(HWND(NIL),PChar(strError),'Sheriff Error',MB_OK or MB_ICONSTOP);
- end;
-
- function CheckLicence:Boolean;
- label reg,1;
- label request,2;
- var
- vRequest:SLS_REQUEST;
- vPermit:SLS_PERMIT;
- vLicenceInfo:SLS_LICENCE_INFO;
- bRegister:boolean;
- res:integer;
- begin
- request:
- vRequest.UnitsReserved:=0;
- if(Sheriff.Request(vRequest,vPermit)) then
- begin
- res:=SizeOf(SLS_LICENCE_INFO);
- Sheriff.QueryLicenceInfo(vLicenceInfo);
- CheckLicence:=true;
- FormMain.SetRunMode(true);
- FormMain.SetAccessLevel(vPermit.AccessKey);
- exit;
- end;
- {Request Failure}
- bRegister:=false;
- if(Sheriff.GetLastError=SLS_E_LICENCE_UNREGISTERED) then
- begin
- if(Sheriff.Register(szProductName,szLicencePath)=false) then
- begin
- ShowSheriffError;
- CheckLicence:=false;
- exit;
- end;
- bRegister:=true;
- end;
-
- if(bRegister or (Sheriff.GetLastError=SLS_E_LICENCE_UNDEFINED)) then
- begin
- {Licence not registered yet}
- reg:
- res:=RegisterForm.ShowModal;
- if(res=mrYes) then
- begin
- {to register licence}
- LicenceForm.SetSheriff(sheriff);
- LicenceForm.ShowModal;
- if(LicenceForm.IsLicenceOK=false) then
- goto reg;
- {licence has been registered successfully}
- if(Sheriff.QueryLicenceInfo(vLicenceInfo)=false) then
- begin
- ShowSheriffError;
- CheckLicence:=false;
- exit;
- end;
- goto request;
- end else
- if(res=mrNo) then
- begin
- {to skip registration and continue as demo}
- {add code here to take appropriate action}
- CheckLicence:=true;
- FormMain.SetRunMode(false);
- exit;
- end else
- if(res=mrCancel) then
- begin
- {to exit}
- end;
- CheckLicence:=false;
- exit;
- end else
- if(Sheriff.GetLastError=SLS_E_LICENCE_EXPIRED) then
- begin
- { Licence has expired, to renew }
- { add code here }
- end else
- if(Sheriff.GetLastError()=SLS_E_LICENCE_EXCEEDED) then
- begin
- { Too many concurrent users, to take action }
- { add code here }
- end;
-
- {Other errors}
- ShowSheriffError();
- CheckLicence:=false;
- end;
-
- begin
- Application.Initialize;
- Application.CreateForm(TFormMain, FormMain);
- Application.CreateForm(TAboutBox, AboutBox);
- Application.CreateForm(TRegisterForm, RegisterForm);
- Application.CreateForm(TLicenceForm, LicenceForm);
- Sheriff:=TSheriff.Create(szProductID,szUserName);
- Sheriff.SetSecrets(g_arySecrets);
- FormMain.SetSheriff(sheriff);
- if(CheckLicence=true) then
- begin
- Application.Run;
- Sheriff.Release(vRelease);
- end;
- end.
-
-
-