The Main form contains TTabControl
which can create some tabs, dynamically. Whenever I add a new tab, a frame is created and add into the new tab. And finally, I will save all these TTabItem
into a TList
.
TForm1 = class(TForm)
TabControl1: TTabControl;
procedure TForm1.AddNewTab;
var
profileFrame :TProfileFrame;
begin
profileFrame := TProfileFrame.Create(Self);
//TabItem
TabItem := TabControl1.Add();
inc(tab_name_Count);
tabItem.Text := tab_name_Count.ToString;
//
profileFrame.Parent := tabItem;
tablist.Add(TabItem);
end;
And this is my frame:
TProfileFrame = class(TFrame)
Name: TEdit;
Gender: TComboBox;
Finally, how can I get the (Name) and (Gender) value in the frame, and print it out in main form? If let say i created 4 tabs, each tabs has its own frame, how can i get the value from different frame?? Im super confuse and new to Delphi.
The main problem is your frames' variable are procedure local variable.
I see different ways to solve your problem.
First: using
TObjectList
:Or you can use another way (checked on Delphi 10.1 FMX Project). You have to change your procedure like this:
Now your frame has owner:
TabItem
. AndTabItem
has components. We can use it:P.S. You can use
for ... in ... do
instead offor ... to ... do
, it can be better, but it's up to you.