home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sheriffa / slsdemo.dpr < prev    next >
Encoding:
Text File  |  1998-07-26  |  3.8 KB  |  146 lines

  1. program SlsDemo;
  2.  
  3. uses
  4.   Windows,
  5.   Forms,
  6.   Dialogs,
  7.   Buttons,
  8.   SysUtils,
  9.   Controls,
  10.   MainForm in 'MainForm.pas' {FormMain},
  11.   SlsApi in 'SlsApi.pas',
  12.   About in 'About.pas' {AboutBox},
  13.   CSheriff in 'CSheriff.pas',
  14.   RegisterFrm in 'RegisterFrm.pas' {RegisterForm},
  15.   LicenceFrm in 'LicenceFrm.pas' {LicenceForm};
  16.  
  17. {$R *.RES}
  18.  
  19. const
  20.   szProductID: array[0..32] of Char = '9758-3050-1918-9292-6466'#0;
  21.   szProductName: array[0..32] of Char = 'Sheriff Demo Delphi'#0;
  22.   szLicencePath: array[0..32] of Char = 'c:\temp'#0;
  23.   szUserName: array[0..32] of Char = 'Trial'#0;
  24.   g_arySecrets:TSecrets =
  25.   (
  26.     ($76,$3E,$6D,$36,$14,$14,$6D,$B8,$1D,$CA,$F3,$D5,$34,$2D,$08,$BC,$14,$31),
  27.     ($00,$B7,$17,$00,$43,$FC,$C0,$7F,$8F,$A2,$22,$D2,$1B,$62,$B3,$DE,$95,$3F),
  28.     ($AC,$2E,$39,$6F,$45,$D5,$41,$11,$43,$41,$2B,$75,$9C,$B2,$67,$6E,$14,$02),
  29.     ($79,$52,$9A,$49,$97,$8B,$1C,$15,$64,$B7,$BE,$6C,$7F,$18,$C3,$4E,$78,$87)
  30.   );
  31.  
  32. var
  33.   Sheriff:TSheriff;
  34.   vRelease:SLS_RELEASE;
  35.  
  36. procedure ShowSheriffError;
  37. var    strError:string;
  38. begin
  39.     Sheriff.GetLastErrorMessage(strError);
  40.     MessageBox(HWND(NIL),PChar(strError),'Sheriff Error',MB_OK or MB_ICONSTOP);
  41. end;
  42.  
  43. function CheckLicence:Boolean;
  44. label reg,1;
  45. label request,2;
  46. var
  47.   vRequest:SLS_REQUEST;
  48.   vPermit:SLS_PERMIT;
  49.   vLicenceInfo:SLS_LICENCE_INFO;
  50.   bRegister:boolean;
  51.   res:integer;
  52. begin
  53. request:
  54.     vRequest.UnitsReserved:=0;
  55.     if(Sheriff.Request(vRequest,vPermit)) then
  56.     begin
  57.         res:=SizeOf(SLS_LICENCE_INFO);
  58.         Sheriff.QueryLicenceInfo(vLicenceInfo);
  59.         CheckLicence:=true;
  60.         FormMain.SetRunMode(true);
  61.         FormMain.SetAccessLevel(vPermit.AccessKey);
  62.         exit;
  63.     end;
  64.     {Request Failure}
  65.     bRegister:=false;
  66.     if(Sheriff.GetLastError=SLS_E_LICENCE_UNREGISTERED) then
  67.     begin
  68.         if(Sheriff.Register(szProductName,szLicencePath)=false) then
  69.         begin
  70.             ShowSheriffError;
  71.             CheckLicence:=false;
  72.             exit;
  73.         end;
  74.         bRegister:=true;
  75.     end;
  76.  
  77.     if(bRegister or (Sheriff.GetLastError=SLS_E_LICENCE_UNDEFINED)) then
  78.     begin
  79.         {Licence not registered yet}
  80.     reg:
  81.         res:=RegisterForm.ShowModal;
  82.         if(res=mrYes) then
  83.         begin
  84.             {to register licence}
  85.             LicenceForm.SetSheriff(sheriff);
  86.             LicenceForm.ShowModal;
  87.             if(LicenceForm.IsLicenceOK=false) then
  88.                 goto reg;
  89.             {licence has been registered successfully}
  90.             if(Sheriff.QueryLicenceInfo(vLicenceInfo)=false) then
  91.             begin
  92.                 ShowSheriffError;
  93.                 CheckLicence:=false;
  94.                 exit;
  95.             end;
  96.             goto request;
  97.         end else
  98.         if(res=mrNo) then
  99.         begin
  100.             {to skip registration and continue as demo}
  101.             {add code here to take appropriate action}
  102.             CheckLicence:=true;
  103.             FormMain.SetRunMode(false);
  104.             exit;
  105.         end else
  106.         if(res=mrCancel) then
  107.         begin
  108.             {to exit}
  109.         end;
  110.         CheckLicence:=false;
  111.         exit;
  112.     end    else
  113.     if(Sheriff.GetLastError=SLS_E_LICENCE_EXPIRED) then
  114.     begin
  115.     { Licence has expired, to renew }
  116.     { add code here }
  117.     end    else
  118.     if(Sheriff.GetLastError()=SLS_E_LICENCE_EXCEEDED) then
  119.     begin
  120.     { Too many concurrent users, to take action }
  121.     { add code here }
  122.     end;
  123.  
  124.     {Other errors}
  125.     ShowSheriffError();
  126.     CheckLicence:=false;
  127. end;
  128.  
  129. begin
  130.   Application.Initialize;
  131.   Application.CreateForm(TFormMain, FormMain);
  132.   Application.CreateForm(TAboutBox, AboutBox);
  133.   Application.CreateForm(TRegisterForm, RegisterForm);
  134.   Application.CreateForm(TLicenceForm, LicenceForm);
  135.   Sheriff:=TSheriff.Create(szProductID,szUserName);
  136.   Sheriff.SetSecrets(g_arySecrets);
  137.   FormMain.SetSheriff(sheriff);
  138.   if(CheckLicence=true) then
  139.   begin
  140.      Application.Run;
  141.      Sheriff.Release(vRelease);
  142.   end;
  143. end.
  144.  
  145.  
  146.