Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2024-03

I can't exit this component

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Arí Ricardo Ody
In the method below, after running TSaveDialog I cannot proceed. Anywhere I
click always reopens TSaveDialog. The OnClose event is executed. I know
because I placed a ShowMessage on this event.
====================================================
procedure TfrmGeraString.tedtNomArqMicEnter(Sender: TObject);
var auxstr : TFileName;
begin
  if rbTransMainframe.checked then
     if opdArqmicro.Execute then
        tedtNomArqMic.Text := opdArqmicro.FileName
     else
  else
     begin;
       auxstr := tsdArqString.InitialDir;
       tsdArqString.Title := 'Informe nome que ser? gravado no micro';
       tsdArqString.DefaultExt := '';
       tsdArqString.FileName := '';
       if tsdArqString.Execute then
          tedtNomArqMic.Text := tsdArqString.FileName
       else;
       tsdArqString.InitialDir := auxstr;
     end;
  btnAvanca.SetFocus;
end;
============
Regardless of whether I click Save or Cancel, when I click on the next
component of the form, the TSaveDialog is always triggered again.
The only TSaveDialog event that has an associated action is OnClose, which
executes a ShowMessage and closes.
Can someone explain to me where I'm going wrong,
please?========================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20240329/e28e10d8/attachment.htm>

Reply by email

Alexey T.
to Arí Ricardo Ody

When something like this happens, do this

- put a breakpoint inside TSaveDialog.Execute
- get the undesired appearing of SaveDialog. see the breakpoint in IDE activated.
- call 'View / Debug windows / Call Stack' IDE window and see it - it shows where code came from

Alex

Reply by email

Werner Pamler
to Arí Ricardo Ody: In the method below, after running TSaveDialog I cannot proceed. Anywhere I click always…
Ar? Ricardo Ody wrote
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.

Reply by email

Martin Frb
to Werner Pamler
Werner Pamler wrote 7 lines
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.

Reply by email

Arí Ricardo Ody
to Alexey T.: When something like this happens, do this - put a breakpoint inside TSaveDialog.Execute -…

I gave up using "OnEnter". Apparently this doesn't work right. I switched to using the "OnClick" event.
Thank you for your help.

Greetings from S?o Paulo - Brazil

On Fri, Mar 29, 2024 at 8:52?AM Alexey T. via lazarus <

Show quoted text 17 lines
wrote: When something like this happens, do this - put a breakpoint inside TSaveDialog.Execute - get the undesired appearing of SaveDialog. see the breakpoint in IDE activated. - call 'View / Debug windows / Call Stack' IDE window and see it - it shows where code came from Alex -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20240330/ff020f5a/attachment.htm>

Reply by email

Arí Ricardo Ody
to Werner Pamler: The "Enter" in this method name indicates that you assigned the event handler to the…

I was thinking that OnEnter would refer to receiving focus. If it responds to mouse movement then it is explained.

I changed the logic to use the OnClick event in the component. Then it worked.

I see now that it was a lack of knowledge on my part.

Thank you very much.

On Fri, Mar 29, 2024 at 9:03?AM Werner Pamler via lazarus <

Show quoted text 15 lines
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. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20240330/0483e287/attachment.htm>

Reply by email

Marc Weustink
to Arí Ricardo Ody

The onenter is indeed fired when the control gets focus. However if you show a dialog in that event, the control loses focus and gets it again when the dialog is closed, resulting in a loop. In general it is bad coding to have much logic in onenter/onleave events

I once was confronted with an app which checked if you didn't leave an empty mandatory edit. If so, the app set the focus back to the control you left. But if you navigated to the next empty mandatory edit it ran into an endless loop focussing both edits

Marc

"Ar? Ricardo Ody wrote 26 lines
I was thinking that OnEnter would refer to receiving focus. If it responds to mouse movement then it is explained. I changed the logic to use the OnClick event in the component. Then it worked. I see now that it was a lack of knowledge on my part. Thank you very much. On Fri, Mar 29, 2024 at 9:03?AM 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. > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus >

Reply by email

Arí Ricardo Ody
to Marc Weustink

Nice explanation.

Thank you very much.

On Sat, Mar 30, 2024 at 4:20?PM Marc Weustink via lazarus <

Show quoted text 48 lines
wrote: The onenter is indeed fired when the control gets focus. However if you show a dialog in that event, the control loses focus and gets it again when the dialog is closed, resulting in a loop. In general it is bad coding to have much logic in onenter/onleave events I once was confronted with an app which checked if you didn't leave an empty mandatory edit. If so, the app set the focus back to the control you left. But if you navigated to the next empty mandatory edit it ran into an endless loop focussing both edits Marc On March 30, 2024 1:50:14 PM GMT+01:00, "Ar? Ricardo Ody via lazarus" < > wrote: >I was thinking that OnEnter would refer to receiving focus. If it responds >to mouse movement then it is explained. > >I changed the logic to use the OnClick event in the component. Then it >worked. > >I see now that it was a lack of knowledge on my part. > >Thank you very much. > >On Fri, Mar 29, 2024 at 9:03?AM 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. >> -- >> _______________________________________________ >> lazarus mailing list >> >> https://lists.lazarus-ide.org/listinfo/lazarus >> -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20240401/9d0d8f37/attachment.htm>

Reply by email