TTabControl Tabs property does not respect user-assigned objects
Original Reporter info from Mantis: markusm
-
Reporter name: Markus M
Original Reporter info from Mantis: markusm
- Reporter name: Markus M
Description:
The Tabs property of a TTabControl is of type TStrings, and one would expect it to behave much like a normal TStringList. In particular, associating an object with a tab (by assigning to Tabs.Objects[Index], or using Tabs.AddObject(Title, Object) to add a new tab), and retrieving the object later (with Tabs.Objects[Index]) ought to return the object originally assigned. I can confirm this does indeed work in Delphi 4, and Delphi documentation at http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/ComCtrls_TTabControl_Tabs.html suggests that this is the correct behaviour:
"Tabs can also contain objects associated with the labels, using the TStrings Objects property."
However, on Lazarus, accessing Tabs.Objects[Index] will return an unnamed TTabSheet instance, and it appears to always be the same instance for any valid value of Index.
Steps to reproduce:
- Add a new tab with an associated object to a TTabControl using Tabs.AddObject(Title, Object), or associate an object with an existing tab using Tabs.Objects[Index] := Object for some non-nil Object
- Immediately access the object using Tabs.Objects[Index]. The value returned will not be that set in step 1.
Additional information:
I've reproduced this on Linux gtk2 (2.0.8 on Arch and 2.0.0 on Debian) and Windows win32 (2.0.6), so I'm assuming this is not widgetset-specific.
I've attached a very basic test program to demonstrate the bug. TabControlTest is simply a conversion of DelphiTabcontrolTest. Sample output:
Delphi 4 (expected):
Tab 2: TestComponent2 (TComponent)
Tab 3: TestComponent3 (TComponent)
Tab 4: TestComponent4 (TComponent)
Tab 3: TestComponent3 (TComponent)
Tab 2: TestComponent2 (TComponent)
Tab 1: TestComponent1 (TComponent)
Lazarus:
Tab 2: (TTabSheet)
Tab 3: (TTabSheet)
Tab 4: (TTabSheet)
Tab 3: (TTabSheet)
Tab 2: (TTabSheet)
Tab 1: (TTabSheet)
Mantis conversion info:
- Mantis ID: 37216
- Version: 2.0.8