Delphi 的批量修改的方法
如一个数组 aa[1..48] 要把他们实时显示在 edit1 .. edit48 应该如何写?edit1.text:=aa[1];
edit2.text:=aa[2];
...
...在VB中有text1(x) 的办法,请问在Delphi 中有没有简单的方法能用 for 。

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
    begin
        for i:=1 to 48 do
        TEdit(self.FindComponent('edit'+inttostr(i))).Text:=aa[i];
    end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    const
      aa: array[1..3] of string = ('AA', 'BB', 'CC');
    var
      I, Index: Integer;
    begin
      // 以下代码未处理异常;
      for I := 0 to ComponentCount - 1 do begin
        if not (Components[I] is TEdit) then Continue;
        Index := StrToInt(Copy(Components[I].Name, 5, Length(Components[I].Name) - 4));
        TEdit(Components[I]).Text := aa[Index];
      end;
    end;end.
    这种方法可能不是最好的,方法很多。