How to use for in with TTabControl in Delphi FMX?

  

Sorry if this is a duplicate question but I didn’t find a solution anywhere.

I want to make a for in to search for a specific tag on my many tabbed TTabControl component, but I have no clue on how to do this.
My TTabControl named TabControl1 receives its tabitems during runtime by a query. It has to be designed to support from 1 to 100+ tabs if the client wants it.
So each tab has a description which is its name and an index on my category table, each time I create a TTabItem, I assign it a tag which is the tab index on my sql table

SQL::
DROP TABLE IF EXISTS Category;
CREATE TABLE Category (
CAT_ID integer primary key
, CAT_Descr Varchar(200)
);

Delphi::
FDQ.Close;
FDQ.Open(‘SELECT * FROM Category’);
while not FDQ.Eof do
begin
TabControl1.Add().Tag := FDQ.FieldByName(‘CAT_ID’).AsInteger;
FDQ.Next;
end;

For my testing purposes I have 5 items on the database: ([1, tab1], [2, tab2], [3, tab3], [4, tab4], [5, tab5])
So when I run the code, it creates 5 tabs with a tag from 1 to 5 on them, great, the tag works. But now I need to populate these tabs with items made in runtime also from a query and now is the part where the for in will happen, but that’s where I don’t know how to make it loop properly on the tabs

procedure TfListing.createtabs;
var
dummytoolbar: TToolBar;
dummylabel: TLabel;
dummylistbox: TListBox;
tabitem: TTabItem;
dummylistitem: TListBoxItem;
begin
// listboxitemlabel
// listboxitemdetaillabel

for DM.FDQ.FieldByName(‘CAT_ID’).AsInteger in TabControl1.Tabs[].Tag do <<== this is the line with the issue
begin
try
dummytoolbar := TToolBar.Create(tabitem);
dummytoolbar.Parent := tabitem;
dummytoolbar.Align := TAlignLayout.Top;

dummylabel := TLabel.Create(dummytoolbar);
dummylabel.Parent := dummytoolbar;
dummylabel.Align := TAlignLayout.Contents;
dummylabel.StyleLookup := ‘toollabel’;
dummylabel.Text := DM.FDQ.FieldByName(‘CAT_Descr’).ToString;
dummylabel.TextAlign := TTextAlign.Center;

dummylistbox := TListBox.Create(tabitem);
dummylistbox.Parent := tabitem;
dummylistbox.Align := TAlignLayout.Client;

dummylistitem := TListBoxItem.Create(dummylistbox);
dummylistitem.Parent := dummylistbox;
dummylistitem.Height := 44;

dummylabel := TLabel.Create(dummylistitem);
dummylabel.Parent := dummylistitem;
dummylabel.Align := TAlignLayout.MostLeft;
dummylabel.StyleLookup := ‘listboxitemdetaillabel’;
dummylabel.Text := dm.FDQ.FieldByName(‘PRO_Stock’).AsString;

dummylabel := TLabel.Create(dummylistitem);
dummylabel.Parent := dummylistitem;
dummylabel.Align := TAlignLayout.Client;
dummylabel.StyleLookup := ‘listboxitemlabel’;
dummylabel.Text := dm.FDQ.FieldByName(‘PRO_Name’).AsString;

finally
dummytoolbar.DisposeOf;
dummylabel.DisposeOf;
dummylistbox.DisposeOf;
dummylistitem.DisposeOf;
end;
end;
end;

How can I make it work?

Comments are closed.