How to convert a String to TNotifyEvent in Delphi?

3

I want to change the OnTimer event of a TTimer in my project at run time, I tried as follows: Timer1.OnTimer:= ('close'); But Delphi reports this: (E2010 Incompatible types: 'TNotifyEvent' and 'string') , how can I convert String 'Close' to TNotifyEvent ?

    
asked by anonymous 29.10.2015 / 01:31

2 answers

3

To use an .INI file; First create an .ini file with the example content:

[P_LOG]

command = test

Function to read the .ini file:

function TForm1.LeIni(sIndice, sCampo: string): string;
var
  ArqIni: TIniFile;
begin
  try
    Result := '';
    ArqIni := TIniFile.Create(ExtractFilePath(Application.ExeName) +'Teste.ini');
    try
    Result := Trim(ArqIni.ReadString(sIndice, sCampo, ''));
    finally
    ArqIni.Free;
    end;
  except
    ShowMessage
    ('Não foi possível encontrar o arquivo de Parâmetros .ini');
  end;

end;

Using the

procedure TForm1.Button3Click(Sender: TObject);
 var
  ConteudoArquivoINI :String;
begin
 ConteudoArquivoINI := LeIni('P_LOG', 'comando')) the
end;
    
31.10.2015 / 19:46
3

You should send a Procedure to the Ontimer, not a String. If your intent with the Close String is to close the Form is simple, create a Procedure with the type (Sender: TObject) with the Close command:

procedure FecharFormulario(Sender: TObject);
begin
  Close;
end;

For the OnTimer Event you do:

Timer1.OnTimer := FecharFormulario;
    
29.10.2015 / 09:39