Topic: 30-Day Trial and Purchase

To All,
I would like to add a 30-Day Trial period to my program.  And then when it is purchased, to remove or ignore the Trial message.
-
I found a posting by Jean.Brezhonek on 2020-02-07 (Trial and Activate Key) that provides a procedure that tells the user how many days are left in the trial and then sends them to my website to purchase the software.
-
The procedure does seem to work as it should.
I do get the Information message when I open my program. When I respond to the message and say YES it takes me to my website.  That's great.
-
Now I'm wondering what happens when the user does purchase the program?  How do we tell my program that it has been purchased and not to display the Demo message?
-
I pretty much understand how the procedure works but since my Pascal skills are limited, I'm not sure about how to perform the last step.
-
Thanks, Frank

2 (edited by brian.zaballa 2020-09-27 22:57:31)

Re: 30-Day Trial and Purchase

You can add another registry for checking if the application is purchased then add a condition somewhere in your program. Hope this attachment helps you figure it out.

Post's attachments

Attachment icon frank_purchase.zip 494.33 kb, 344 downloads since 2020-09-28 

brian

Re: 30-Day Trial and Purchase

Brian,
Thanks for the quick response.
It looks really good and should be what I need.
-
Tomorrow I'll get into the code and see how it works. Going through the code is a good learning exercise for me.
-
I've learned so much from the folks on the forum.  I wouldn't be as far as I am without all the help from folks like yourself.
-
One of my goals is to learn more about Pascal so I can do stuff like this myself. (I've definitely got a ways to go)
-
Thanks again and stay safe
Frank

Re: 30-Day Trial and Purchase

Hello papafrankc, Hello Brian


Try this snippet : After 30 days trial, it will shows a nag screen

procedure Form1_OnShow (Sender: string; Action: string);
var   reg: TRegistry;
       iDays: integer;
      sKey: string;
begin
     sKey := '';
     reg := TRegistry.Create;
     reg.Access := KEY_ALL_ACCESS;
     reg.RootKey := HKEY_CURRENT_USER;
     reg.OpenKey('software\'+APP_NAME,true);
     if not reg.ValueExists('StartDate') then reg.WriteDate('StartDate', Now+30); // trial period is 30 days

     iDays := Trunc(reg.ReadDate('StartDate')) - Trunc(Now); // time left days
     sKey := reg.ReadString('Key');

     reg.CloseKey;
     reg.Free;

     if sKey<>'' then
     begin
         if CheckKey(sKey) then Exit;
     end;

     if iDays < 1 then
     begin
          frmNagScreen.lbTrial.Caption := 'Trial period is over.';
          frmNagScreen.ShowModal;
          Exit;
     end;

     isAllowRun := True;
     frmNagScreen.lbTrial.Caption := 'Demo version. Time left: ' + IntToStr(iDays) +' days.';
     frmNagScreen.ShowModal;

end;


procedure frmNagScreen_bOrderPage_OnClick (Sender: string; var Cancel: boolean);
begin
    OpenUrl('http://yourpage.com');
end;

function CheckKey(sKey: string): boolean;
begin
    Result := False;
    if (sKey='FJKS-TJKS-WEEW-NMVV') or
       (sKey='NNMF-QPOV-FDDK-ZUIF') or
       (sKey='VCJK-RGJJ-CWER-GHFJ') then Result := True;
end;


begin

end.


Hope this can help you
JB

5 (edited by domebil 2020-09-28 06:12:48)

Re: 30-Day Trial and Purchase

see this example

http://myvisualdatabase.com/forum/viewtopic.php?id=1434

Domebil

Re: 30-Day Trial and Purchase

Jean,
I just started working on your 30-day solution.  But I get an error as follows:
   reg.OpenKey('software\'+APP_NAME,true);
   The error is Undeclared Identifier: 'APP_NAME'
-
Do you have any idea why I might be getting this error?
Thanks, Frank

7 (edited by CDB 2020-11-14 06:29:06)

Re: 30-Day Trial and Purchase

papafrankc,


Did you try substituting APP_NAME  with the actual name of your program, or, make a constant called APP_NAME referring to your program name including the .exe?

On a clear disk you can seek forever

Re: 30-Day Trial and Purchase

Hello papafranck, hello CDB

Have you declare as CONST the name of your application ?
To dot it, on the very first line of your script, enter this line :

const
  APP_NAME = 'My App Name';

This must be enterd on two lines

JB

Re: 30-Day Trial and Purchase

CDB,
I replaced APP_NAME with RecordsX.exe and still got the same error.
Then I tried 'RecordsX.exe' and I did not get an error but I got the same error when it went to the frmNagScreen_bOrderPage_OnClick procedure
-
My lack of pascal is showing I'm afraid.
Frank

Re: 30-Day Trial and Purchase

CDB, Jean,
I put the CONST 2 lines on the beginning of the script and got the same error saying that frmNagScreen is an Undeclared Identifier.
-
I don't know if it is relevant but I don't have any form called frmNagScreen ?

11 (edited by CDB 2020-11-14 07:42:45)

Re: 30-Day Trial and Purchase

Papafrankc,

I think this needs to be a global constant, so will need to be at the top of the script file, before any procedure or functions.

You can either write:
CONST
   APP_NAME = 'records.exe';

and then in the function   APP_NAME

or

CONST
   APP_NAME = records.exe;

in the nag screen function  'APP_NAME' either should work.


If you copied and pasted JB's code, you might have missed changing some of Jean's frmNagScreen to the name of your own 'nag' forms' name.

PS. Sorry JB I didn't see your reply when I was typing mine.

On a clear disk you can seek forever

Re: 30-Day Trial and Purchase

CDB,
In your reply I see: ...frmNagScreen to the name of your own 'nag' forms' name.
So I'm guessing there should be a form called frmNagScreen
Since I don't have a NagScreen form I'm thinking that might be my problem.
Is there a standard NagScreen form I can use or do I have to create one myself?
Thanks, Frank

13

Re: 30-Day Trial and Purchase

papafrankc wrote:

CDB,

So I'm guessing there should be a form called frmNagScreen


Yes


Is there a standard NagScreen form I can use or do I have to create one myself?
Thanks, Frank


You need to create it yourself.  As you are creating the form yourself, you can call it whatever you want, making the appropriate changes in the code to reflect your choice of name.

On a clear disk you can seek forever

14 (edited by papafrankc 2020-11-15 05:02:10)

Re: 30-Day Trial and Purchase

Hi CDB,
First, I get an error of Undeclared Identifier at isAllowRun
To get around it I commented it out.  Now the procedure runs but I'm wondering what isAllowRun is supposed to do? And is not having it causing me problems?
-
Next, I have created a form frmNagScreen
Here's what I have on the form:
- a label - lbTrial
- a button - bOrderPage  Note: the OnClick event calls my website (This works OK)
- a TextBox - sKey           Note:  I'm thinking maybe this will be used to input the KEY?
-
Here's where I'm getting confused
-
I'm not sure where and how I am supposed to save the KEY? I'm saving it in a TextBox but I'm not sure this is correct?
It looks to me like the KEY needs to be saved in the Registry but if so then HOW?
-
I also thought in case the user types an Incorrect KEY that they should receive a message box that says INVALID KEY. but I haven't been able to make that work.
-
And just for my education I have a thought that I'd like your opinion on.
To Save and check for a valid key would it be possible to save the Key Codes in a table and then when the user inputs a Key Code, to check for it in the table?
It seems to me that we're doing the same thing by storing a code in the Registry.
-
Any help on these last steps will be appreciated.
Thanks, Frank

15

Re: 30-Day Trial and Purchase

Papafrankc


JB is the man to ask as that is his code snippet.


I'd be wary about saving the serial numbers to a table unless you can encode them (which is possible) as otherwise anyone with copy of SQL Browser or SQL Studio would be able to open the database, read and take your keys.


To save the key to registry all you need is to write:

reg.WriteString('Key', 'sKey');

Assuming that sKey now contains the serial entered via your textbox.

On a clear disk you can seek forever

Re: 30-Day Trial and Purchase

Hi CDB
Thanks for the reply.
-
Hi Jean,
If you get the chance could you please check out my previous reply and let me know what you think?
-
Thanks, Frank

Re: 30-Day Trial and Purchase

Hello papafranck, hello CDB

About trial snippet :

1 - IsNotAllowRun ....means that if SnagScreen is not already launched, the form that will trigger it will be closed when SnagScreen is displayed. It is a control instruction.
2 - There are three things to keep in mind in the code I posted to you:

- Procedure Form1.OnShow : If you are in the correct interval of dates, it checks if you have the registration key by going to read it in the registry key via  sKey := reg.ReadString('Key');
If the value is different from empty (if sKey <> ''), it reads the content (your registration key) via function CheckKey.
If the value it reads matches the one entered by the user (in fact the one you gave it), your application goes on,without displaying theSnagScreen.
Otherwise, it appears, indicating that the test time has been exceeded.

- As CDB says, a secure user key is not written in a separate table, that any good hacker (not even necessarily a good one) can go digging to find the key.
The best solution is to write this key in the registry,base what is done via the procedure  frmNagScreen_bEnterKey_OnClick

- But you must allow the user to enter this key.
You then create a separate form allowing him to enter this key.
From SnagScreen, you link to this form.
The must, you allow it to do it from this screen: When you click on the link, you extend the SnagScreen by this integrated form.
But take it step by step and you will improve later .
The procedure I just mentioned will write the key entered (from the key validation form) in the registry base (reg.WriteString('Key', frmNagScreen.edKey.Text or your form.edKey.Text);

In summary, the verification of a valid key is done in three steps:
When starting your application:
-Verification of the validity of the test duration (StartDate +30)
- Reading a key in the registry. If absent and if the test date has passed, the SnagScreen appears (CheckKey function)
- If no key in the registry, possibility for the user to enter it (via your key entry form)

If you bought a version of MVD, this is how it works.
And above all, never write any key in a readable table without difficulty (but with the right tools as CDB said)

I hope this will help you. I would have given you an example of a key entry for one of my applications, but my hard drive let me down (COVID 19?)
I would have to rummage through my backup hard drive (Phew!)

JB

Re: 30-Day Trial and Purchase

Jean,
Thanks for the explanation.
-
One thing I have noticed when I've been testing the procedure is that I think there are entry(s) in my Registry that are left over from my various tests. So when I try to run a test now I'm getting remaining days that are incorrect.
-
Is there a way to clear the entries so I can start fresh?
-
I know just enough about the Registry to be dangerous (lol).  I'm hesitant to go into it and start deleting things.  When I go into the Registry I see a number of entries for Records.exe but I'm not sure what they are all for?
-
If I can delete the proper Registry entries then I should be able to do accurate testing to make sure everything is working OK.
-
Thanks, Frank

Re: 30-Day Trial and Purchase

Frank,
If you are using JB's script, then you should see your app name under the SOFTWARE folder in the Registry. Click on your app name and the registry entries for your app will be in the right side panel. Right-Click on each entry and select DELETE. It's ok to delete your own entries since your app should be rewriting them. You definitely do not want to mess with any other software entries, so be sure you are on your own app entry.

Re: 30-Day Trial and Purchase

Hi EHW,
Thanks for the guidance. It's pretty simple now that I know where to look.
-
I actually have 2 app folders.  RecordsX and RecordsX.exe.  There's probably because of what I was doing when I was trying to get the procedure to work.
-
I was able to delete one of the entries under each app.  However there is another entry called Ab Default in each one and it won't let me delete them.  Is it OK to leave them there?
-
Also, what about right clicking on the App name itself and deleting them?  I didn't try it because I wanted to check with you first..
-
Thanks, Frank

Re: 30-Day Trial and Purchase

Yes you can remove the app name also.

Re: 30-Day Trial and Purchase

Hi EHW & Jean,
Resetting the Registry entry for my program works great smile
-
Everything in the procedure works great down to this point:
*******************
sKey := reg.ReadString('Key');
showMessage('Key = '+sKey);
     reg.CloseKey;
     reg.Free;

     if sKey<>'' then
     begin
         showMessage('I am in sKey not = space');

         if CheckKey(sKey) then Exit;
     end;
*******************
Note: I put in the showmessage so I could see what is in sKey
Since sKey is ' ' it never opens CheckKey
-
This is pretty much where I'm stuck.
-
CDB said to do the following to write the Key Code into sKey
To save the key to registry all you need is to write:

reg.WriteString('Key', 'sKey');

Assuming that sKey now contains the serial entered via your textbox.
-
I'm not sure how or where to do this?
-
Thanks for helping me through this, Frank

23 (edited by ehwagner 2020-11-16 03:24:03)

Re: 30-Day Trial and Purchase

Yes, CDB is correct with how to write the key to the Registry. When the trial period is over you can show a form stating such and have a text field where they can enter the key that you provided them (one of the ones in your IF STATEMENT). Once they enter the key you can then use CDB's WriteString statement to store it in the Registry. From that point on your program will read the Regisrtry key and since it is one of the ones in your IF Statement, your program will allow your user to continue using your software. Hope this makes sense.

Re: 30-Day Trial and Purchase

Thanks for the quick response.
It does make sense so I'll work on making it happen,
Frank

25 (edited by papafrankc 2020-11-16 05:27:19)

Re: 30-Day Trial and Purchase

Here's what I have:
I have a TextBox and a button to save the Key
I added the procedure to the OnExit Event as below but it doesn't seem to save the Key. I added this procedure to the OnExit event for the SAVE button.
-
procedure frmNagScreen_Button2_OnExit (Sender: TObject);
var
   reg: TRegistry;

begin
  reg.Access := KEY_ALL_ACCESS;
  reg.RootKey := HKEY_CURRENT_USER;
  reg.OpenKey('software\RecordsX.exe',true);
  Reg.WriteString('Key', 'sKey');
end;

-
When I run the procedure and hit the SAVE button the NagScreen closes and the program opens up.  However when I exit the program and re-start it, I get the NagScreen again.
-
I'm sorry to be such a pest, but I think I'm getting closer smile
Frank