或者 2.给每个控件Tag赋值, for i := 0 to Form1.ComponentCount - 1 begin if Form1.Components[i].ClassNameIs('TLabel') then begin case Form1.Components[i].Tag of 1:ss:='1'; 2:ss:='2'; ... end; TLabel( Form1.Components[i]).Caption:=ss; end; end;
为什么显示出来 是空白的? -------------- var i:integer; ss:string; begin for i := 0 to 3 do begin if Form1.Components[i].ClassNameIs('TLabel') then begin case Form1.Components[i].Tag of 1:ss:='1'; 2:ss:='2'; 3:ss:='3'; end; TLabel(Form1.Components[i]).Caption :=ss; end; end; end;
6楼: var MyLabel:array [1..3] of TLabel; ... procedure TForm1.FormCreate(Sender: TObject); var si:integer; begin for si:=1 to 3 do begin MyLabel[si]:=TLabel.Create(Self); with MyLabel[si] do begin Parent:=Form1; Left:=.. Top:=.. Font... Caption:=... end; end; end; ... var i:integer; begin for i:= 1 to 4 do begin MyLabel[i].Caption :=IntToStr(i); end; end;
----------------------------------------------
-
bjdribllec 你看 ----- var i:integer; ss:string; begin for i := 0 to 4 do begin if Form1.Components[i].ClassNameIs('TLabel') then begin case Form1.Components[i].Tag of 1:ss:='1'; 2:ss:='2'; 3:ss:='3'; 4:ss:='4'; end; TLabel(Form1.Components[i]).Caption :=ss; end; end; end;
----------------------------------------------
向大家学习。