Board index » cppbuilder » accessing controls in the order of their TabOrder

accessing controls in the order of their TabOrder


2005-11-15 05:46:53 AM
cppbuilder33
Hello,
this turned out to be harder than i expected it to be, or I'm
simply missing something that's very clear. I have already
searched archives and couldn't find an answer.
question:
I simply want to go through all the children of a WinControl in
the order of their TabOrder and print their names. How can I do
this?? I don't want the Children of the Children of WinControl.
Just want the Children of a WinControl. Oh.. and these children
could have TabStop true or false -- doesn't matter.
I tried two functions:
1) GetTabOrderList -- problem is it give you WinControl's
children and their children too.
2) FindNextControl -- problem is its only availabel for CLX
(right?) i tried useing it and the compiler complained that
it is not accessible. When I checked in BCB help, it has that
yellow square (which, I believe indicates clx properties,
funcitons, etc)
Only solution I can come up with now is traversing through each
of the WinControl's children and looking fo their TabOrder..
0 the first time, 1 the second time.. but this is O(n squred).
I figure there's gotta be a better way... something BCB already
provides us with.
Please respond if you know the solution. Sorry, if this is too
easy, but I'm clearly not getting it.
thanks,
vp
 
 

Re:accessing controls in the order of their TabOrder

"Palle Meinert" < XXXX@XXXXX.COM >wrote:
Quote
Both function should work and both function are in the vcl.
thanks for your response, Palle.
Quote

I just tried by placing a few edit fields...
seemed to work alright.
yes. it works because you don't have controls that have
children! It will not work if you have say two panels on a
form and each panels have, say, two buttons.
When you use your code on form, it will give you six things: 2
panels and 4 buttons. what I want is just the children of that
control.. i.e in our example just the two panels.
thanks for your help. I will try to derive a class and see
if i can publish FindNextControl method.
cheers,
vp
 

Re:accessing controls in the order of their TabOrder

Both function should work and both function are in the vcl.
I just tried by placing a few edit fields, a button and a memo and placed
the following code in the button onclick event:
TList *TabOrderList = new TList();
GetTabOrderList(TabOrderList);
Memo1->Clear();
for (int ix=0; ix < TabOrderList->Count; ++ix)
{
Memo1->Lines->Add(static_cast<TComponent*>(TabOrderList->Items[ix])->Name);
}
delete TabOrderList;
It seemed to work alright.
If you want to know what the yellow sqaures in the help means then just
click the legend link in the header of the method-list. It tells that
methods with yelllow squares are protected, which i guess mean that they are
only availible in derived classes like e.g. TForm (where they are also
listed without the yellow square).
/Palle
 

{smallsort}

Re:accessing controls in the order of their TabOrder

thanks gambit and Palle. your responses were very helpful. I
am about to try that.
thanks,
vp
 

Re:accessing controls in the order of their TabOrder

"vp" < XXXX@XXXXX.COM >wrote in message news:437913dd$ XXXX@XXXXX.COM ...
Quote
1) GetTabOrderList -- problem is it give you WinControl's
children and their children too.
That is because tab orders appliy to parent-child relationships. If you
have parents A, B, and C, and B has tabbable children, then when focus is
passed to B via tabbing then all of the children of B are tabbed through
before focus is then passed to C.
Quote
FindNextControl -- problem is its only availabel for CLX (right?)
That is not correct. FindNextControl() is a public method of TWinControl,
and is available in VCL as well.
Quote
i tried useing it and the compiler complained that it is not accessible.
That is correct. It is declared as protected in TWinControl. Use
SelectFirst/Next() for public access.
Quote
When I checked in BCB help, it has that yellow square (which, I believe
indicates clx properties,
funcitons, etc)
No. A yellow square indicated protected access. All CLX items are
contained in the CLX documentation, and all VCL items are contained in the
VCL documentation. They are not mixed. The top of the topic page indicates
whether you are looking at a topic in the CLX or VCL documentation.
Quote
Only solution I can come up with now is traversing through each
of the WinControl's children and looking fo their TabOrder..
0 the first time, 1 the second time.. but this is O(n squred).
I figure there's gotta be a better way... something BCB already
provides us with.
Borland does not provide public access to what you are asking for. The
VCL/CLX does internally keep track of a per-parent tab order list, but it is
private in TWinControl. You only have access to FindNextControl() in
derived classes.
Gambit
 

Re:accessing controls in the order of their TabOrder

Quote
yes. it works because you don't have controls that have
children! It will not work if you have say two panels on a
form and each panels have, say, two buttons.
Then extend my previous code with a call to a this function instead of
GetTabOrderList
void TForm1::ChildTabList(TWinControl* Sender, Classes::TList* List)
{
Sender->GetTabOrderList(List);
for (int ix=List->Count-1; ix>= 0; --ix)
{
if (static_cast<TWinControl*>(List->Items[ix])->Parent != Sender
|| !static_cast<TWinControl*>(List->Items[ix])->TabStop)
{
List->Delete(ix);
}
}
}
As parameter specify whatever control you would like to get the a list of
child control of together with a TList to return them in. If you don't care
about the tabstop property then remove the last condition of the if
sentence.
/Palle
 

Re:accessing controls in the order of their TabOrder

"vp" < XXXX@XXXXX.COM >wrote in message news:437923c3$ XXXX@XXXXX.COM ...
Quote
When you use your code on form, it will give you six things: 2
panels and 4 buttons. what I want is just the children of that
control.. i.e in our example just the two panels.
After you get the list, you can run through the items removing any items
that do not have the desired control as their immediate Parent. For
example:
void __fastcall GetTabOrder(TWinControl *AParentControl, TList *AList,
bool IncludeGrandChildren = false)
{
AParentControl->GetTabOrderList(AList);
if( !IncludeGrandChildren )
{
for(int x = AList->Count-1; x>= 0; --x)
{
if( static_cast<TWinControl*>(AList->Items[x])->Parent !=
AParentControl )
AList->Delete(x)'
}
}
}
Gambit