Henry Olive 5 Posted April 2, 2021 (edited) I have 6 Labels on my form I need to fill them according to a query result but i dont know how many data returns ( may be NONE may be 1 may be 6 ( which is MAX) I wrote below codes var MyLabel : TLabel; while not Query1.Eof do begin if Query1.Fields[0].AsString <> '' then begin MyLabel.Caption :=Query1.Fields[0].AsString + ' - Responsible :'; MyLabel.Caption := dm.GetNextDocNo(MyLabel.Name); // i find next label.caption // Above dm.GetNextDocNo function Increases number in a string) which works well // for example if MayLabel.Name ='Label1' then this function makes it 'Label2' so on // My problem is in below how can i get Label.Name from Label.Caption ? // so that I can fill other labels ? MyLabel := ??? end; Query1.Next; end; Edited April 2, 2021 by Henry Olive Share this post Link to post
David Heffernan 2345 Posted April 2, 2021 Put the labels in an array, and then access them by index, or Use a single label, and include linebreaks in the caption, or Create the labels dynamically, or Probably some other solutions that I have not thought of. 1 Share this post Link to post
Guest Posted April 2, 2021 (edited) hi @Henry Olive you can try this... the order of each label will be used to "not repeat replacement on before-label". my Panel will be used to restrict my container domain search you see? procedure TForm1.btn_Go_Change_Label_CaptionsClick(Sender: TObject); var lMyArrayRecords: TArray<string>; i : integer; begin // lMyArrayRecords representing the records returned by your SQL... lMyArrayRecords := [ { } 'record 1 value', 'record 2 value', 'record 3 value', 'record 4 value', 'record 5 value', { } 'record 6 value', 'record 7 value', 'record 8 value', 'record 9 value', 'record 10 value' { } ]; // for i := low(lMyArrayRecords) to high(lMyArrayRecords) do begin if (i > (Panel1.ControlCount - 1)) then break; // get out here... // if (Panel1.Controls[i] is TLabel) then TLabel(Panel1.Controls[i]).Caption := lMyArrayRecords[i]; end; end; hug Edited April 2, 2021 by Guest Share this post Link to post