Topic: Trial and serial part 2

Hello everyone and thank you for reading my request. I've searched and read all the threads in the forum regarding developing code to create test versions.
What I managed to create is attached, I put my hand on the fire that you will be horrified at what you will see.
Aside from assuming there will be numerous fixes to be made, what I haven't been able to do is prevent re-registration if the software is already registered.
Thanks to all and greetings.

Post's attachments

Attachment icon Prova.zip 325.74 kb, 128 downloads since 2023-04-25 

Re: Trial and serial part 2

//*** verifica la registrazione del prodotto ***
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\Tod1618',true);
     if not reg.ValueExists('StartDate') then reg.WriteDate('StartDate', Now+10); // periodo di prova 10 giorni

     iDays := Trunc(reg.ReadDate('StartDate')) - Trunc(Now); // Giorni rimanenti
     sKey := reg.ReadString('Key');
     reg.CloseKey;
     reg.Free;

     if sKey<>'' then
       begin
           if CheckKey(sKey) then
           begin
             Form2.edPk.Text := sKey;
             Form2.bAttiva.Enabled := False;
             Form2.edPk.Enabled := False;
             Exit;
           end;
       end;

     if iDays < 1 then
       begin
         if MessageDlg('Il periodo di prova è finito!'+#10+' Vuoi visitare la pagina per ordinarlo?', mtInformation, mbYes+mbNo, 0) = mrYes
           then OpenUrl('http://esempio.com');
             Form2.show;
             Form1.Close;
           Exit;
       end;
End;

3 (edited by reteinformatica 2023-04-26 11:01:38)

Re: Trial and serial part 2

Thank you Vladimir. It was what I needed. Is there anything that could be improved in the code I wrote?

4 (edited by reteinformatica 2023-04-27 19:25:51)

Re: Trial and serial part 2

Hi everyone,
I set only 1 day for the expiration of the trial to test its behavior right away.


    if iDays < 1 then
       begin
         if MessageDlg('Il periodo di prova è finito!'+#10+' Vuoi visitare la pagina per ordinarlo?', mtInformation, mbYes+mbNo, 0) = mrYes
           then OpenUrl('http://esempio.com');
             Form2.show;
             Form1.Close;
           Exit;
       end;

The problem arises when it expires.
Form2 which should allow registration opens for a moment and then the whole program closes, effectively not allowing the program to be registered.
Where could I put the Form1.close statement so that the program closes only if not registered?

Thanks to all and a greeting.

Post's attachments

Attachment icon Prova.zip 325.74 kb, 99 downloads since 2023-04-27 

Re: Trial and serial part 2

Hi Fabio


procedure Show -  Shows the form.


procedure ShowModal - Use ShowModal to show a form as a modal form. A modal form is one where the application can't continue to run until the form is closed. Thus, ShowModal does not return until the form closes.

6 (edited by pavlenko.vladimir.v 2023-04-27 20:55:01)

Re: Trial and serial part 2

procedure registr;
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\Tod1619',true);
  if not reg.ValueExists('StartDate') then reg.WriteDate('StartDate', Now+10); // periodo di prova 10 giorni

  iDays := Trunc(reg.ReadDate('StartDate')) - Trunc(Now); // Giorni rimanenti
  sKey := reg.ReadString('Key');
  reg.CloseKey;
  reg.Free;

  if sKey<>'' then
  begin
    if CheckKey(sKey) then
    begin
      Form2.edPk.Text := sKey;
      Form2.bAttiva.Enabled := False;
      Form2.edPk.Enabled := False;
    end else if IDYES = MessageDlg('Errore di registrazione!'+#10+' Il programma ha rilevato una chiave di registrazione non valida, vuoi cambiare '+
                        ' la chiave?', mtInformation, mbYes+mbNo, 0) then
                        begin
                          Form2.TagString := 'register';
                          Form2.ShowModal;
                        end else Form1.Close;
    end else
    begin
      if iDays < 1 then
      begin
        if IDYES = MessageDlg('Il periodo di prova è finito!'+#10+' Vuoi visitare la pagina per ordinarlo?', mtInformation, mbYes+mbNo, 0)then
        begin
        Form2.TagString := 'register';
        Form2.ShowModal;
        end else Form1.Close;
      end;
    end;

end;
Post's attachments

Attachment icon Prova.rar 5.93 kb, 117 downloads since 2023-04-27 

Re: Trial and serial part 2

Hi sparrow and vladimir.
Thanks for the usual and clear information. I was missing this showmodal property.
Do you think there is anything in this code that could be improved?

Re: Trial and serial part 2

Vladimir gave you a good code, it may look a bit confusing to you.


As for your code, its lower part needs to be changed.
From the condition "if MessageDlg('Versione di prova tempo rimanente:..." to the end, everything looks strange.

Re: Trial and serial part 2

Ok, I understood everything. Thanks sparrow and Vladimir.

Re: Trial and serial part 2

Hi
the project that Vladimir have attached  is also what I needed.
A couple of quick questions :

1- What is the registry code and how can I find or change it?

2- Is the registry code fixed or can it be random based on each computer?

thanks a lot for the great help