Solved

Guaranteed order TTabsheets are read from TPageControl thru Controls[]

Posted on 2011-09-28
6
477 Views
Last Modified: 2012-06-27
HELP! I asked a similiar question awhile back and am still frustrated with the same issue. I'm writing a generic function that will be used in many forms.

Actually I'm reading all Controls on a form in order (i hope). However, when I get to a certain TPageControl and read it's child controls thru PageContolPtr->Controls(i) I DO NOT get the TTabSheets in order. The PageControl has 4 TTabSheets. For any individual TabSheet I've verified that TabOrder = TabIndex = PageIndex. It is. However using PageContolPtr->Controls(i) it reads Tab0, Tab2, Tab3 and then Tab1. How do I read them Tab0, Tab1, Tab2, Tab3?

Please, can anyone help on this.

Thanks
Pat
0
Comment
Question by:flins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
George Tokas earned 500 total points
ID: 36813317
Hello there,
Again a question belongs to C++ Builder topic area.
I don't know if my post will help you but I will mention AGAIN that if this question doesn't attracted my attention as "Neglected Question Alert" I wouldn't post this.
Anyway:
All of us (developers using C++ Builder or Delphi) AND I AM NOT AN EXCEPTION tend to forget very useful properties of the controls we are using.
One of them is the "Tag" property and it is of integer type.
Check out that by default ALL controls you use in the form has Tag = 0.
So "Guaranteed order TTabsheets .."
Set the Tag property of the first TTabSheet a number and increment by one in the next and so on...
It will be good NOT to start with a 0(zero) in order not to mess with other controls, try 100 as a base or whatever number you decide.
Check the Tag property of the tabsheet and you will know which tabsheet it is.

George Tokas.
0
 

Author Closing Comment

by:flins
ID: 36903355
I'm accepting this solution since effort wasn't made by anyone else. The actual solution, and eiither something I don't understand in Borland or a Borland bug, is to save the Form with TabSheet 0 as the active TabSheet. I've since found that if any TabSheet other than TS 0 is active at save time, the TabOrder, TabIndex, etc are meaningless.
0
 

Author Comment

by:flins
ID: 36903413
I'd like to add an additional comment. The Form in question has one PageControl with 4 TabSheets. The TabSheets were created in order TabSheet1, TabSheet2, TabSheet3 and TabSheet4. If TabSheet1 is the active TabSheet when the form is saved, the TabOrder, TabIndex and PageIndex are precisely 0,1,2 and 3 as I would expect. When TabSheet 2 is the active TabSheet at save time, the TabOrder, etc are 0, 3, 1, 2. It makes no sense to me.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:George Tokas
ID: 36903863
>>It makes no sense to me.
Unfortunately it MAKES SENSE to me...
Thanks for accepting the answer by the way.
NOW:
The order of tabsheets inside the page control depending on the active page in design phase.
By "default" BCB assumes that YOU WANT this particular tabsheet as the default active one and enumerates the rest in incremental order.
Except the proposal I made to be SURE about the order using the tag property, you can use the following at TForm constructor:
PageControlx->ActivePage = TabSheet1;
This way regardless of the active page is set in design time allways will use TabSheet1 at runtime.
The SAME problem I had some years ago and to tell the true I allways set the first as default in designtime since I didn't use the method you are using.
One more thing: There are not many people here knowing how to use the VCL with C++ Builder but the safer way to get an answer - fast - is to post in C++ Builder topic area..
AT LEAST I will try to help you and I hope and more people.
This question was "Neglected Question Alert" for me via email, but I am monitoring every day the C++ Builder topic area.


George Tokas.
0
 

Author Comment

by:flins
ID: 36906004
gtokas,

I understand your explanation above. However, let me ask the following. Let's call the 4 TabSheets T1 - T4. When T1 is the active page on save, the TabSheet (TabOrder) is T1 = 0. T2 = 1, T3 = 2 and T4 =  3. When T2 is the active page the TabOrder is T1 = 0, T2 = 3, T3 = 2 and T4 = 2. Why? The TabSheets were definifely and absolutely created in the exact order of T1, T2, T3 and T4.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 36908544
Hello again,
I have to dig a bit about this.
I told you that I am not using the method you are using.
I assume that all tabsheets inside the pagecontrol is meant to be used for one task so that is the reason you are "circling" through controls.
This problem appeared to me back in 2005 when a colegue of mine used this way and solved using the tag the way I proposed before. There was a huge mess happened before we realise where was the problem because the application created a data file depending with the order and there were many pagecontrols and tabsheets mostly created at runtime.
Imagine an application controls multiple clients and creates configuration and report files for each one at runtime in a LAN depending on a kind of database.
To save coding space this colegue used circling through controls to find out what group the control had to respond and called the handler. Imagine 100 buttons because that was one of the cases.
So intead of the method he used we set the tag property and retrieve it from "Sender" and used it as parameter. Same used and to pagecontrols panels and more the application had.
This way saved us from using loops when they don't needed and the code was less - and faster -after eliminated check loops.
Now for the tabsheet order I have to dig a bit at the magazine and I will be back.

George Tokas.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C language IDE – Compilers installation 14 78
Unresolved External Symbols 3 130
Header of docx file 17 132
Embarcadero C++ Builder XE10.1 Berlin red arrow Indicator 2 75
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question