Recent

Author Topic: Revisit to calling OnExit / OnEditingDone event  (Read 3177 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Revisit to calling OnExit / OnEditingDone event
« on: July 12, 2021, 07:06:09 am »
I had posted this content a while ago, but recently I tested it again and hope this is resolved at Lazarus IDE level.  I'm on Windows 10.

Problem is when a control (e.g. TMemo) loses focus by clicking mouse on another form or another application (e.g Webbrowser) than Lazarus application, the control does not issue OnExit or other events. For general controls this is not a big problem.

But when the control is RTTI control, e.g. TtiMemo, etc., the changes done to now is lost. You can see the difference quite easily.

Create a form, and put TMemo, TtiMemo and TButton,  and set TTIMemo's Lisk as tiobject to the TMemo and property to Lines. You don't have to assign any action to TButton's Onclick event. 

If you change anything in TMemo, the changes are reflected in TTIMemo immediatly. If you click on a webbrowser on the same PC, the focus is lost but the changes of content remain there. You may come back and continue the work.

Next, try enter any text in TTIMemo. TMemo's content will not change, until you click on the TButton.  Clicking on the space of the form does not work.

The problem happens when you change the content of TTIMemo (without changing TMemo's content), and the click on a web browser (or any other application on the PC). Then the changes done in the TTIMemo goes away.

Hope I have some way to save before exit the application.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Revisit to calling OnExit / OnEditingDone event
« Reply #1 on: July 12, 2021, 08:24:43 am »
What you're looking for is the form's OnDeactivate/OnActivate events, which should happen when you change of window and back. OnExit is only called when you change of control inside the same window.

You could set some kind of flag to keep track of which control you're in (using its OnEnter event) and check it in the form's  OnDeactivate to know which action, if any, you have to take.

ETA: Note that OnDeactivate is not published so it doesn't appear in the object inspector; you'll have to declare and set it in code.
« Last Edit: July 12, 2021, 08:33:42 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: Revisit to calling OnExit / OnEditingDone event
« Reply #2 on: July 12, 2021, 09:50:51 am »
Quote
What you're looking for is the form's OnDeactivate/OnActivate events,

I don't think so. Activate/deactivate does not seem to be called when I move around focus between applications on the Windows.

What I'm looking for is to detect when the rtti control (and any others) lose focus. Losing focus should call OnExit event. But this is called when the focus move within the Lazarus form, but not between Windows applications.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Revisit to calling OnExit / OnEditingDone event
« Reply #3 on: July 12, 2021, 10:00:24 am »
I can't test on Windows ATM but in my Linux boxes here it does exactly that: if you change from one form to another, the event fires on the first, and the same happens if you change to another application.*

As, in fact, it's suppossed to do: OnActivate/OnDeactivate are the equivalent, for forms, other controls's OnEnter/OnExit.


* Sorry, I've actually tested changing of application and you're rigth, it doesn't fire. :-[

I know there is some way of doing it but I don't remember what it is; let me investigate a little ...

Later: OK, right event, wrong object. It's the Application's OnDeactivate. You can use it by setting it in code or using a TApplicationProperties component.

Sorry for my misleading first comments :-[
« Last Edit: July 12, 2021, 10:19:32 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Revisit to calling OnExit / OnEditingDone event
« Reply #4 on: July 12, 2021, 05:52:57 pm »
Drop a TApplicationProperties on the form and implement the OnDeactivate event..

That should fire when you switch to a different app.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018