Recent

Author Topic: How do you ensure that certain events are handled at the form level?  (Read 1002 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
When a control and the main form are programmed to handle the same event and the control has focus when the event occurs how is it handled?

Say I have a TEdit that responds to the OnKeyDown event and the form also has its OnKeyDown effect,what happens if I press a key when the TEdit has focus?

Can the form override the handling, or will the edit control prevent it happening on the form?

When TEdit handles the event  can it also pass the event to the Form for the form to process it in its event handler?
Lazarus 3.0/FPC 3.2.2

Thaddy

  • Hero Member
  • *****
  • Posts: 16198
  • Censorship about opinions does not belong here.
Re: How do you ensure that certain events are handled at the form level?
« Reply #1 on: February 28, 2024, 05:14:00 pm »
Yes and Yes. If the TEdit has focus it will have precedence over any other event. And yes, you can force any other event to fire after the Tedit is ready, by setting that in code of the Tedit event.
But why would you want that? Looks bad design.
(Although on a low level this can be done, but then you need your own components)
« Last Edit: February 28, 2024, 05:22:10 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Re: How do you ensure that certain events are handled at the form level?
« Reply #2 on: February 28, 2024, 06:57:50 pm »
Yes and Yes. If the TEdit has focus it will have precedence over any other event. And yes, you can force any other event to fire after the Tedit is ready, by setting that in code of the Tedit event.
But why would you want that? Looks bad design.
(Although on a low level this can be done, but then you need your own components)

This is what I wanted to be sure of, whether the TEdit would have to explicity call the Form's event, or whether they would fire one of the other.

If the control is not one that receive's focus that happens? Some controls that don't receive focus can respond to key events such has hotkeys.

Quote
But why would you want that? Looks bad design.

Its a continuation of this topic Lazarus method of listing all objects that can get focus, hot keys and clicks? where every control which has some events it responds to is provided with a  floating combination of keys that can trigger the required actions.
Lazarus 3.0/FPC 3.2.2

 

TinyPortal © 2005-2018