var Edits: array [0..5] of TEdit; // 把所有的Edit当成是数组 procedure TForm1.Button1Click(Sender: TObject); var i, j: integer; begin for i := 0 to ComponentCount - 1 do begin // 循环控件 if Components[i] is TEdit then Edits[i] := Components[i] as TEdit; end; (* Edits[0] := Edit1; // 先要赋值才能 才能给Text赋值 Edits[1] := Edit2; Edits[2] := Edit3; Edits[3] := Edit4; Edits[4] := Edit5; Edits[5] := Edit6; *) // Edits[0].Text := ‘aaa‘; j := 0; for i := 0 to Length(Edits)-1 do begin Edits[i].Text := ‘这是Edit‘ + IntToStr(j); // 赋值 Inc(j); end; end;
总会有方便的时候,每个控件都是数组的成员。
时间: 2024-10-24 08:54:21