In an android app, in a ListBox i'm creating ListBoxItems, into each Item a reactangle and into each rectangle i'm ctreating 5 labels all this dynamically in RUN TIME, 5 labels for each Listboxitem created. The only unique property of the labels is the name who changes for each listboxitem that created. Now, i can't find a way to find a specific label to change its text property. I can find in which Listboxitem and by extension which rectangle is the Label i want ( with tag_num variable) but i cant determine the specific label to change its text.
the code of creatig the Listboxitems
...
lbim := TListBoxItem.Create(ListBox1);
lbim.Parent := ListBox1;
lbim.TextSettings.Font.Size := 12;
lbim.StyledSettings:=
[TStyledSetting.Family,TStyledSetting.Style,TStyledSetting.FontColor];
lbim.Text := LJsonValue1_2.Value;
lbim.Height := 50;
lbim.Margins.Top := 2;
rctg := TRectangle.Create(lbim);
rctg.Parent := lbim;
rctg.Align := TAlignLayout.Client;
rctg.Stroke.Kind := TBrushKind.Solid;
rctg.Stroke.Color := $FF51ABAE;
rctg.Stroke.Thickness := 1;
rctg.Tag := tag_num;
rctg.OnClick:=QuantityClick;
rctg.Margins.Left:=2;
rctg.Margins.Right:=2;
rctg.Index := -5;
lb := TLabel.Create(rctg);
lb.Parent := rctg;
lb.Align := TAlignLayout.Center;
lb.TextSettings.HorzAlign := TTextAlign.Leading;
lb.Width := 150;
lb.Name := 'value0_'+IntToStr(tag_num);
lb.TextSettings.Font.Size := 12;
lb.StyledSettings:=
[TStyledSetting.Family,TStyledSetting.Style,TStyledSetting.FontColor];
lb.Margins.Right := 180;
lb.Margins.Bottom := 35;
lb.Text := LJsonValue1_1.Value;
lb1 := TLabel.Create(rctg);
lb1.Parent := rctg;
lb1.Align := TAlignLayout.Center;
lb1.TextSettings.HorzAlign := TTextAlign.Trailing;
lb1.Width := 150;
lb1.Name := 'value1_'+IntToStr(tag_num);
lb1.TextSettings.Font.Size := 12;
lb1.StyledSettings:=
[TStyledSetting.Family,TStyledSetting.Style,TStyledSetting.FontColor];
lb1.Margins.Bottom := 35;
lb1.Margins.left := 180;
lb1.Text := LJsonValue4_2.Value;
...
tag_num:=tag_num+1;
and so on... It is possible to created from 1 ListBoxItem to 15 or more.. How to change, for example the lb1 Label in 10th lIstBoxItem, its text? I find a similar problem here Search for a Label by its Caption but doesnt work for me.. Any ideas?
my search code is :
for i := 0 to ListBox1.Items.Count - 1 do
begin
item := Form1.ListBox1.ListItems[i];
if item.Components[i] is TLabel then
begin
if TLabel(item.Components[i]).Name = 'value1' then
begin
if ed_quant1.Text = '' then
begin
ed_quant1.Text := '0';
TLabel(item.Components[i]).Text := ed_quant1.Text;
end
else
begin
TLabel(item.Components[i]).Text := ed_quant1.Text;
end;
end;
if TLabel(item.Components[i]).Name = 'value2' then
begin
if ed_quant2.Text = '' then
begin
ed_quant2.Text := '0';
TLabel(item.Components[i]).Text := ed_quant1.Text;
end
else
begin
TLabel(item.Components[i]).Text := ed_quant1.Text;
end;
end;
end;
end;
i'll should mention that the search takes place in another form of where the ListBox is created.