Use variables for object name in Delphi

后端 未结 3 824
死守一世寂寞
死守一世寂寞 2021-01-16 13:25

I\'m trying to change the caption of many labels using regular way:

form1.label1.caption := \'1\';
form1.label2.caption := \'2\';
form1.label3.c         


        
3条回答
  •  感动是毒
    2021-01-16 13:57

    If you are sure you have 50 labels label1, label2 .. label50
    The solution could be like this:

    var lbl: TLabel;
    for i:=1 to 50 do
    begin
        lbl := FindComponent('Label'+IntToStr(i)) as TLabel;
        lbl.Caption := IntToStr(i);
    end;
    

提交回复
热议问题