Dynamic Tab Captions

Philippe Sarfati asked:

Does anyone know the correct usage of the property/method $alltabcaptions for a tab pane object?

It's an attribute of a tab pane class, not of the instance. "$cclass.$objs.MyTabPane.$alltabcaptions.$desc" returns:

"The tab captions of all the tabs, separated by carriage returns"

This attribute is not show in the property manager in classic mode, but if you click on a tab pane object on a window in design mode with the notation inspector, you can see it at the end of the "General" tab in Property Manager. Strange ???

I plan to use this like the $tabs attribute for a tab strip to get/set captions of my tab pane object dynamically in runtime mode. Any ideas?

Here is my reply:

I don't think you're going to be very happy trying that. Since $alltabcaptions is a property of the class, making changes to it won't have any effect on the current instance, but it WILL make a PERMANENT change to the class (and therefore any future instances of that class). On the other hand, you could set up a list variable in your instance to mimic how you'd like this to work. Let's explore:

First, let's see if we can modify the caption of an unselected tab without noticeably flickering the window. It turns out that we can change the caption of any tab without effectively "jogging" the display like this:

Calculate tempTabNumber as $cinst.$objs.tabpane1.$currenttab
Calculate $cinst.$objs.tabpane1.$currenttab as 2
Calculate $cinst.$objs.tabpane1.$tabcaption as 'Changed'
Calculate $cinst.$objs.tabpane1.$currenttab as tempTabNumber

"tempTabNumber" is a local variable of "Short integer" type. When I did this, I didn't notice any flickering of the screen. This means (to me, at least) that we could set up a list variable to act as "tab caption list" and perform similar operations using the contents of that list. We could build this list in our $construct method using:

Do tabcaptionlist.$cols.$add('caption',kCharacter,kSimplechar,25)
Calculate tempTabNumber as $cinst.$objs.tabpane1.$currenttab
For tab from 1 to $cinst.$objs.tabpane1.$tabcount step 1
  Calculate $cinst.$objs.tabpane1.$currenttab as tab
  Do tabcaptionlist.$add($cinst.$objs.tabpane1.$tabcaption)
End For
Calculate $cinst.$objs.tabpane1.$currenttab as tempTabNumber

"tabcaptionlist" is an instance variable of "List" type. "tab" is a local variable of "Short integer" type. The line number in "tabcaptionlist" is equivalent to the tab number for the caption on that line. We could make changes to this list however we want and then sychronize the tab captions like this:

Calculate tempTabNumber as tabPaneRef.$currenttab
For tab from 1 to tabcaptionlist.$linecount step 1
  Calculate tabPaneRef.$currenttab as tab
  Calculate tabPaneRef.$tabcaption as tabcaptionlist.[tab].caption
End For
Calculate tabPaneRef.$currenttab as tempTabNumber

"tabPaneRef" is an instance variable of "Item reference" type that makes this more convenient. It initializes with a value of "$cinst.$objs.tabpane1".

I put this code in a method of my tab pane named "$updatecaptions", so I can now call it from anywhere within the window using:

Do tabPaneRef.$updatecaptions()

In the demonstation library is provide a datagrid for changing the captions in the list and a pushbutton to trigger the update of the captions, but you can do these things within any method in your window.