控件數組

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;

 總會有方便的時候,每一個控件都是數組的成員。數組

相關文章
相關標籤/搜索