1 (edited by papafrankc 2022-09-29 01:20:52)

Topic: Nag Screen Trial Period

Hi,
I have a Nag screen that I use to administer a 15 day FREE Trial period.  If the date is within the 15 day period then the user can go ahead and continue the trial.
.
If the trial period reaches 0 then this code kicks in:
   if iDays = 0 then
    begin
      showMessage('----- Trial Period Has Ended -----') ;
      frmNagScreen.SetFocus
    end else
      frmNagScreen.close ;

.
This works fine.
However I noticed today that if the user doesn't come back to the program for a few days the iDays will go to -1 or -2 ....
Since IDays is NOT 0, then it lets the user continue to use the program.
.
I need to check for 0 and/or -1 at the same time.
Using my code above I can check for 0 or -1 separately, but not both at the same time.  I'm guessing I could maybe do it with an OR function but I haven't been able to make it work.
.
UPDATE: I just tried if iDays <= 0 then... and it worked because right now idays is 0.  So I guess I'll wait till tomorrow to see if it works for idays = -1, unless you have any suggestions?
SORRY: It looks like <= is not working after all.  So I'm back to my original problem.
.
As always your help will be appreciated.
Thanks
Frank

Re: Nag Screen Trial Period

// процедура проверки регистрации
procedure registrKey;
var
   reg: TRegistry;
   iDays: integer;
   sKey,k: string;
begin
     sKey := '';
     reg := TRegistry.Create;
     reg.Access := KEY_ALL_ACCESS;
     reg.RootKey := HKEY_CURRENT_USER;
     reg.OpenKey('software\serviceSoft', True);//+APP_NAME - имя вашей программы
     if not reg.ValueExists('onSoft') then reg.WriteDate('onSoft', Now+20); // демо версия (Now+20)=20 дней
     iDays := Trunc(reg.ReadDate('onSoft')) - Trunc(Now); // time left days
     sKey := reg.ReadString('Key');
     reg.CloseKey;
     reg.Free;

     delete(skey,1,pos('-',sKey));
     if sKey=EncryptRC5(GetHardDiskSerial(ExtractFileDrive (paramstr(0))),'ljhfljhvgi\-9одлы6ш8енр') then
     begin
       if (frmRegistr.Tag=1) then frmRegistr.Tag:=0;
       frmRegistr.pRegistr.Visible:=False;
       frmReception.caption:='Lite service';
     end else begin
        if iDays < 1 then
            begin
             frmRegistr.Tag:=1;
             if IDYES = MessageBox(iniLanguage.ReadString('lang','messagex1','Пробный период закончился, перейти к регистрации?'), iniLanguage.ReadString('lang','messagex2','Регистрация '), MB_YESNO+MB_ICONINFORMATION) then frmRegistr.ShowModal else frmlogin.Close;
            end else
              // настройте на свой вкус, что если программа не зарегестрированна
              frmReception.caption:=frmReception.caption+' '+ iniLanguage.ReadString('lang','messagex4','Осталось')+ ' ' + IntToStr(iDays) +' '+ iniLanguage.ReadString('lang','messagex3','Дней');
       end;

Re: Nag Screen Trial Period

Vladimir,
Thank you for the code example.
When I was looking through your code I got an idea so I checked my code and found out that I was really close.
It turned out that I was declaring the variable iDays twice.  So I was resetting the variable to 0 when it should have left it at iDays = 15.
Once I got rid of the second declaration my code now works OK.
.
Thanks
Frank