Show hint only when the application starts for the first time

5

I have a desktop application that is a bit complicated, so I thought about helping the user to generate images (Hints) to help with the path.

But I know how annoying this is, so I wonder if this is only possible when the application is first run.

I could try to do something like Do not show this tip again, but I'm not using the database ... Is it possible to do this without using a database?

    
asked by anonymous 05.02.2016 / 19:12

1 answer

5

Yes, you can do without using the Database, just save this information in the Windows Registry as mentioned in the comment of the friend @Paruba, we can write to the folder HKEY_CURRENT_USER , let's create a folder inside that folder with the name of our system, and within that folder we will create a record with the information you want!

Function to read the registry:

function frmteste.LerRegistro: Boolean;
const
  vRaiz: String = 'Nome_Seu_Sistema';
var
  Registro: TRegistry;
begin
  Result := False;
  //Chama o construtor do objeto
  Registro := TRegistry.Create;
  with Registro do
  begin
    // Somente abre se a chave existir
    if OpenKey(vRaiz, False) then
    begin
      //Validando se ja abriu ou não...
      if ValueExists('Hint_Inicial') then
      begin
        if (ReadInteger('Hint_Inicial') = 1) then
          Result := True;
      end;
      // Fecha a chave e o objeto
      Registro.CloseKey;
      Registro.Free;
    end;
  end;
End;

With this function, you can find out if you have already opened the System or if it is the first execution, then in Create we will implement the recording of this information:

procedure frmTeste.FormCreate(Sender: TObject);
const
  vRaiz: String = 'Nome_Seu_Sistema';
var
  Registro: TRegistry;
begin
  {Se não encontrou o Registro, Cria o Registro informando...
  ...que ja mostrou o Hint Inicial}
  if (LerRegistro = False) then
  begin
    //Chama o construtor do objeto
    Registro := TRegistry.Create;
    { Abre a chave (se o 2°. Parâmetro for True, ele cria a chave caso ela ainda não exista.}
    Registro.OpenKey(vRaiz, True);
    //Aqui passamos 1 como parâmetro, 0 = nunca abriu 1 = ja abriu
    Registro.WriteInteger('Hint_Inicial', 1);
    //Fecha a chave e o objeto
    Registro.CloseKey;
    Registro.Free;
  end;
end;

Now in the% form of% of the main form you implement the reading of the registry:

procedure frmTeste.FormShow(Sender: TObject);
begin
  if LerRegistro = False then
  begin
    {Aqui você chama o procedimento do Hint Inicial
    Chamada da função ou procedimento responsável pelo Hint Inicial.}
  end;
end;

In the example given, the registry folder would have the following structure:

HKEY_CURRENT_USER\Nome_Seu_sistema\Hint_Inicial

Edit:

It is still possible to read and write to a text file at the root of your system, just use a TStringList at the time of the% of the Form% using its properties: Show or Show . But the Best and Most Professional option is to use the method I reported above, write to the Windows Registry!

  

Important Note: Whenever you write a value in the Windows Registry,   Uninstall your System do not forget to remove this entry! Like this   no junk in the User Registry!

I await Feedback!

    
06.02.2016 / 23:38