[c++] borland builder canfocus problem
Thursday, 27. August 2009, 19:17:26
Hi there,
today i want to share with you something that i had discovered today. During my work i got some problems with setting the focus on specified component... well sometimes i got access violation,and that kind of stuff...
The problem could be solved through method that is implemented in all components/objects that are inherited from twincontrol... called CanFocus()... the problem is that this method has also some problems with borland frames... so, the only way is to write your own function to get the same behaviour of the original one...
so, if you're looking to solve problem as mine.. read below to find out the source code...
today i want to share with you something that i had discovered today. During my work i got some problems with setting the focus on specified component... well sometimes i got access violation,and that kind of stuff...
The problem could be solved through method that is implemented in all components/objects that are inherited from twincontrol... called CanFocus()... the problem is that this method has also some problems with borland frames... so, the only way is to write your own function to get the same behaviour of the original one...
so, if you're looking to solve problem as mine.. read below to find out the source code...
ok, the function is very simple...
the only thing we need to know is if the element can have focus it must be... Visible and Enabled... and.. all it's parents should have those properties set in the same way... (enabled)
the second thing is, if we want to have the same functionality it should accept all object that inherits from twincontrol and should return bool value (true/false)... so here it is:
bool CanWeFocusIt(TWinControl *control)
{
while(control)
{
if(!control->Enabled || !control->Visible)
{
return false;
}
control = control->Parent;
}
return true;
}
that's it... nothing more.. i hope i helped someone..














How to use Quote function: