Recent

Author Topic: OnEnter Event ???  (Read 2746 times)

J-G

  • Hero Member
  • *****
  • Posts: 992
OnEnter Event ???
« on: April 14, 2022, 02:20:16 pm »
I'm fairly familiar with 'Events' and can usually understand what is expected (logically) for many but have not had a need to use the [OnEnter] event until today.

It seems to me that an [OnEnter] event ought to fire as soon as the focus is taken by the component (in this case a TEdit). What I want to do is decide whether to allow an edit if a certain flag has been set after an edit in a different TEdit.  To this end I created an [OnEnter] event which just puts a message up asking if the user really does want to 'edit' the value which is dependent upon the previous entry.

When this message didn't appear as expected, I set a break-point at the start of the event but that never 'fired'  - and I can't understand why!
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Zvoni

  • Hero Member
  • *****
  • Posts: 3314
Re: OnEnter Event ???
« Reply #1 on: April 14, 2022, 03:15:51 pm »
Some code, please?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

dseligo

  • Hero Member
  • *****
  • Posts: 1674
Re: OnEnter Event ???
« Reply #2 on: April 14, 2022, 03:16:31 pm »
It fires in Lazarus 2.0.10 and 2.2.0 on Windows 11, I just tried it.

J-G

  • Hero Member
  • *****
  • Posts: 992
Re: OnEnter Event ???
« Reply #3 on: April 14, 2022, 03:24:39 pm »
It fires in Lazarus 2.0.10 and 2.2.0 on Windows 11, I just tried it.
Are you suggesting that my logic is not flawed?  -  just that [OnEnter] is not implemented for a TEdit in Laz 1.6 ?

That would make sense - though somewhat disappointing since the event is listed in the Object Inspector  - and creates a procedure as expected.
« Last Edit: April 14, 2022, 03:27:49 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 992
Re: OnEnter Event ???
« Reply #4 on: April 14, 2022, 03:26:02 pm »
Some code, please?
I doubt that any code would help Zvoni :)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Zvoni

  • Hero Member
  • *****
  • Posts: 3314
Re: OnEnter Event ???
« Reply #5 on: April 14, 2022, 03:26:07 pm »
OnEnter is one of the most basic events, and without knowing i would bet, that it was part of Lazarus in the 0.X-versions, and that it worked there already.

I'm rather guessing there is something else going on
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 992
Re: OnEnter Event ???
« Reply #6 on: April 14, 2022, 03:44:40 pm »
OnEnter is one of the most basic events, and without knowing i would bet, that it was part of Lazarus in the 0.X-versions, and that it worked there already.

I'm rather guessing there is something else going on
This was my thought.

Am I wrong in assuming that using the mouse to 'enter' a TEdit should be thought of as [OnEnter]?

This is the procedure created :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.TPI_ParamEnter(Sender: TObject);
  2. begin
  3.   If UNS then
  4.       ShowMessage('Really?');
  5. end;
  6.  

UNS (Unified Number Series) is a boolean which is set to true in the other TEdit (on condition) but I can't check the status because the break-point (set at 'If UNS then') doesn't get called.


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Zvoni

  • Hero Member
  • *****
  • Posts: 3314
Re: OnEnter Event ???
« Reply #7 on: April 14, 2022, 08:51:53 pm »
Just moving the mouse or clicking into that TEdit?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 992
Re: OnEnter Event ???
« Reply #8 on: April 15, 2022, 12:40:17 am »
Just moving the mouse or clicking into that TEdit?
Clicking into the TEdit in preparation to make an edit.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

dseligo

  • Hero Member
  • *****
  • Posts: 1674
Re: OnEnter Event ???
« Reply #9 on: April 15, 2022, 01:53:29 am »
Create new project.
Put TEdit on a form.
Click on it, go to events on Object inspector, double click OnEnter event (on the right side).
It should create new method (Edit1Enter).
Type this in the body:
ShowMessage('x');

Method should look like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1Enter(Sender: TObject);
  2. begin
  3.   ShowMessage('x');
  4. end;

Run the project.
If the message doesn't show, compress files from project (not exe) and upload it here.

dbannon

  • Hero Member
  • *****
  • Posts: 3744
    • tomboy-ng, a rewrite of the classic Tomboy
Re: OnEnter Event ???
« Reply #10 on: April 15, 2022, 02:18:39 am »
Clicking into the TEdit in preparation to make an edit.

Clicking into the TEdit from outside the TEdit. If you are already in there, clicking in there again will not fire the event....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Josh

  • Hero Member
  • *****
  • Posts: 1454
Re: OnEnter Event ???
« Reply #11 on: April 15, 2022, 08:50:11 am »
hi

earliest i have is 1.9 from 2017, and the event is firing fine.

attached simple project with 3 tedits and 3 tlabels that count every time the event is fired when you either click in and tab into the tedits,

« Last Edit: April 15, 2022, 08:54:58 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

wp

  • Hero Member
  • *****
  • Posts: 13430
Re: OnEnter Event ???
« Reply #12 on: April 15, 2022, 11:48:46 am »
I still have a Laz 1.6.4 on my disk, and josh's demo project runs correctly with it. I don't know what's wrong in your setup.

But maybe you should take this as a hint to upgrade to a recent version. You can keep your old version and install the new version as a "secondary" installation - check the corresponding box in the installer; this leaves your old installation untouched. But note that loading a project created for Laz 1.6 into Laz 2.x will add new properties so that you cannot load the project by Laz 1.6 again... - always use backup copies for such experiements unless you are sufficiently experienced and can undo the changes.

J-G

  • Hero Member
  • *****
  • Posts: 992
Re: OnEnter Event ???
« Reply #13 on: April 15, 2022, 03:26:16 pm »
Apologies for the tardy response - been busy with other parts of the program  :-[

As you will all appreciate, creating a new project (as suggested by dseligo) with just a TEdit and a TLabel shows that the [OnEnter] event does fire as it should - but of course with only one TEdit it fired immediately so wasn't a proper test.

Adding a second TEdit and making that Tab Order 0 forced the original TEdit to correctly test 'On Enter'  - - -  and of course it does.

I now need to look at that part of my program again to see if I can see something I've obviously missed.

@wp I'm aware that it is posible to have multiple versions of FP/Laz installed and yes I have considered it but I've been away from programming for some while so haven't needed any new 'bells and whistles' as yet :)
« Last Edit: April 15, 2022, 03:28:28 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

dseligo

  • Hero Member
  • *****
  • Posts: 1674
Re: OnEnter Event ???
« Reply #14 on: April 15, 2022, 11:29:51 pm »
As you will all appreciate, creating a new project (as suggested by dseligo) with just a TEdit and a TLabel shows that the [OnEnter] event does fire as it should - but of course with only one TEdit it fired immediately so wasn't a proper test.

Adding a second TEdit and making that Tab Order 0 forced the original TEdit to correctly test 'On Enter'  - - -  and of course it does.

Check two things first:
1. Be absolute sure that TEdit's OnEnter event is assigned to method you want to
2. Put some memo on your form (just for testing) and put this in the very beginning of your OnEnter method:
Code: Pascal  [Select][+][-]
  1. Memo1.Append('OnEnter fired');

 

TinyPortal © 2005-2018