Forum > LCL

Are keystrokes automatically bubbled up the parent hierarchy?

(1/2) > >>

vfclists:
When you enter a key which isn't handled by an object that receives key strokes, such as a button, a button or label's hotkey or a TEdit control, will all the items in the parent hierarchy receive the keystroke whether they respond to keys or not?

For instance if a TPanel contains a TEdit which doesn't respond to a key, will the TPanel react to it if the necessary event handlers are in place?

It is it also possible for a parent component to prevent a child component from receiving the event or vice versa?

PS. I just noticed this thread - https://forum.lazarus.freepascal.org/index.php/topic,66621.0.html

Does it have a bearing on this question?

Thaddy:
It is the other way around: the parent window dispatches to the children. So, basically, you can intercept at the parent level and prevent it going to the children.

vfclists:

--- Quote from: Thaddy on September 25, 2024, 02:15:58 pm ---It is the other way around: the parent window dispatches to the children. So, basically, you can intercept at the parent level and prevent it going to the children.

--- End quote ---

Does this mean that although a TPanel on its own doesn't respond to character entry strokes, it can block character entry strokes from getting to a TEdit contained in it?

It doesn't have any OnKeyXXXX events in the properties pane. Does it mean it would have to be cast to an ancestor component which deals with those events before being able to handle them?

rvk:
It's probably easier to just set TForm.KeyPreview to true and use TForm.OnKeyDown.
Set the parameter Key to 0 if you want to block it from going to any other control on the form.

Curt Carpenter:
I did not know that.  Good to know.

Navigation

[0] Message Index

[#] Next page

Go to full version