Recent

Author Topic: Error on AddObject TabControl.Tabs  (Read 6555 times)

morphocr

  • Newbie
  • Posts: 4
Error on AddObject TabControl.Tabs
« on: May 14, 2011, 02:02:11 am »
it works on the combobox.items but not in tabcontrol.tabs and both use tstrings

Code: [Select]

  tmyclass = class
    tt  : integer;
    a   : string;
  end;
.
.
.

procedure TForm1.Button1Click(Sender: TObject);
var
   i      : integer;
   temp   : tmyclass;
begin
     for i := 1 to 10 do
     begin
          temp := tmyclass.Create;
          temp.a:='object#'+inttostr(i);
          temp.tt:=i;
          ComboBox1.Items.AddObject(temp.a,temp);
          TabControl1.Tabs.AddObject(temp.a,temp);
     end;
     for i := 0 to ComboBox1.Items.Count-1 do
     begin
          showmessage(inttostr(tmyclass(ComboBox1.Items.Objects[i]).tt));
          showmessage(inttostr(tmyclass(TabControl1.tabs.Objects[i]).tt));
     end;
end;

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Error on AddObject TabControl.Tabs
« Reply #1 on: May 14, 2011, 10:03:46 am »
What error do you get?
It would also be useful if you give details about Lazarus / Freepascal version, etc.

Gr.
Dirk.

morphocr

  • Newbie
  • Posts: 4
Re: Error on AddObject TabControl.Tabs
« Reply #2 on: May 14, 2011, 11:46:47 pm »
What error do you get?
It would also be useful if you give details about Lazarus / Freepascal version, etc.

Gr.
Dirk.


thanks for your reply,

when trying to get any objects from
Code: [Select]
TabControl1.tabs.Objects[i] it come with -(maxInteger) value instead of the object pointer, and im using the
follow Ide :

- Lazarus Version #: 0.9.30
- Date: 2011-05-13
- FPC Version: 2.4.2
- SVN Revision: 29811M

  for i386-linux-gtk 2 on Fedora 14 Box

morphocr

  • Newbie
  • Posts: 4
Re: Error on AddObject TabControl.Tabs
« Reply #3 on: May 20, 2011, 10:34:20 pm »
anyone follow this ?

eny

  • Hero Member
  • *****
  • Posts: 1586
Re: Error on AddObject TabControl.Tabs
« Reply #4 on: May 20, 2011, 11:56:45 pm »
I'm assuming this is because ComboBox1.Items and TabControl1.Tabs are different beasts.
ComboBox.Items is an actual TStringList (which has the Objects property implemented as expected).
TabControl.Tabs is a TTabControlNoteBookStrings that has some fancy methods (not in the least an overriden PutObject(...)).

Just create a separate TStringList where you store the info you need for your tabs.
All posts based on: Win10 (Win64); Lazarus 1.8.0 'stable' (#56594 win64) unless specified otherwise...