On 29/03/2024 13:03, Werner Pamler via lazarus wrote:
Am 29.03.2024 um 12:09 schrieb Arí Ricardo Ody via lazarus:
procedure TfrmGeraString.tedtNomArqMicEnter(Sender: TObject);
The "Enter" in this method name indicates that you assigned the event handler to the OnEnter event of something (a button maybe). This means that whenever the mouse is moved over this button ("enter") the event fires. Usuall dialogs are displayed only when a "click" occurs, and this responsibility is in the OnClick event of the button.

Actually that would be "MouseEnter".
But good catch.

"TEdt....Enter" => The "OnEnter" of an "TEdit" ?

So, you want the dialog to open when the user "enters" the edit:
- clicks in the edit
- uses Tab-key to go to the edit

Once the dialog closes, you fill the edit with the selected file:
   tedtNomArqMic.Text := opdArqmicro.FileName

I have not tested all of the below:
- When the dialog is closed, then focus would return to the form
- this focuses/enters the edit again => and the dialog opens again

I can see, you want to avoid that, because you set focus away from the edit:
   btnAvanca.SetFocus;


But that is (probably) to late.

If I am right (not tested, just a guess)...

begin
  if rbTransMainframe.checked then
     if opdArqmicro.Execute then
        tedtNomArqMic.Text := opdArqmicro.FileName

// ####### Here the dialog close, and the edit is focused again
// ####### tedtNomArqMicEnter is called from here (recursive)

....
// The below line is not reached in time.

  btnAvanca.SetFocus;
end;


===============================
If that is the case:

procedure TfrmGeraString.tedtNomArqMicEnter(Sender: TObject);
var auxstr : TFileName;
begin
  FIn_tedtNomArqMicEnter then exit;
  FIn_tedtNomArqMicEnter := true;
  try
     /// all your code
  finally
    FIn_tedtNomArqMicEnter := False;
  end;
end;

That way you stop the recursion, and the code to focus the btn should work.

--
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to