1. Computing
in Delphi TIPS :: In complex form designs where you have dozens of controls contained in several containers it is sometimes necessary to find out whether the focused control (the one with the input focus) is a child of some overall parent of a group of controls.

Read the full article to learn how to Implement "Contains Focus" for Delphi's Container Controls: TPanel, TGroupBox, ...

Related:

Comments
April 26, 2010 at 5:19 pm
(1) Silver Warior says:

Hi!
Why not just use OnEnter and OnExit events. Theese are specificaly designed for monitooring wich control has an input focus. And these events fire first for container control (TFrame), then to contained control (TPanel), then for contained control of contained control (TGroupBox), etc. until it reaches the control wich you have selected, by clicking on it or by moving to it with the use of TAB kex (TEdit)

April 27, 2010 at 7:00 am
(2) Zarko Gajic says:

@Silvio: That would work of course, but you would need to write OnEnter/OnExit for every control on a container. Not an ideal solution for this problem, similar to: http://delphi.about.com/od/vclusing/a/coloringfocused.htm

April 29, 2010 at 11:09 pm
(3) Silver Warior says:

I don’t see why? If you need to find out if a TFrame contain a component wich has imput focus, it is the easiest way to use OnEnter/OnExit events. And you could write only OnEnter/OnExit events for TFrame, becouse before OnEnter/OnExit events of a control wich actualy had changed focus are fired, OnEnter/OnExit events of a container control of a control wich actualy had changed are fired. This means that if you have for an instance a TFrame and on this frame you have TPanel and on this panel you have TEdit that when you will click inside Edit and change focus to it first the OnEnter event of TFrame will be fired, then OnEnter event of TPanel, and only then OnEnter event of TEdit.
Ofcourse achiving goal from an article from you previously posted link is completly different mater than achiving goal of this article.

May 4, 2010 at 4:50 am
(4) Zarko Gajic says:

@”Silver Warior” Yes, you are right. However, what if you have 100 frames on a form? Would you write 100 event handlers? You would not, you would write one and assign OnEnter/OnExit to this even handler for all frames. What if each of 100 need to have something else executed in its OnEnter/OnExit…

What I proposed is a generic solution – from my point of view much better than using event handlers. Event handlers should be used to handle events – what the artice is talking about is not an event but a “state”.

May 4, 2010 at 5:32 pm
(5) Silver Warior says:

If you have 100 frames than you know can easily check wich frame has fired the event since you can use TFrame(Sender).SomeProcedure. In this SomeProcedure you write code wich need to happen when the event is fired.

You say that “Event handlers should be used to handle events”. So when is the event fired? It is fired when there is certain change of certain state.

Also based on your code I belive that you would need to recursivly call your code for every frame so you could just figured out wich of those 100 frames contains a component wich has imput focus.
I’m also wandering when will you be looking wich of your frames has an input focus. Will it be just before some function is executed? Will it be periodicaly (use of timer)?

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.