通过unit1给unit2中的10个edit赋值,编译通过,但是没有结果,一个一个的赋值一点问题没有。
for i := 1 to 10 do
begin
  TEdit(findcomponent('form2.edit' + inttostr(i))).text := 'hjkhdja';//这句话能这样写吗?
end;

解决方案 »

  1.   

    TEdit(findcomponent(form2.edit + inttostr(i))).text := 'hjkhdja';
      

  2.   

    TEdit(findcomponent('form2.edit' + inttostr(i))).text := 'hjkhdja';
    findcomponent()里面的参数是个STRING型的。返回值是个TComponent,所以如果你的组件名是form2.edit1,form2.edit2之类,我觉得应该是:
    findcomponent('form2.edit' + inttostr(i)).text := 'hjkhdja';
      

  3.   

    ('form2.edit' + inttostr(i)))
    这句话不对,字符串的相加好象不这样.查查吧
      

  4.   

    错在:'form2.edit'中的'Form2'  在此处不会解释成窗体Form2,而只会当是控件名称中的一部分以下的没问题:procedure TForm1.BitBtn1Click(Sender: TObject);
    var I: Integer;
    begin
      with Form2 do
      begin
        for I := 1 to 10 do
          TEdit(findcomponent('Edit' + inttostr(i))).text := 'hjkhdja';
      end;
      Form2.Show;
    end;
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    const
      NamePrefix = 'form2.MyEdit';
    begin
      for i := 1 to 20 do
      begin
        TEdit.Create(Self).Name := NamePrefix + IntToStr(i);
        with TEdit(FindComponent(NamePrefix + IntToStr(i))) do
        begin
          Left := 10;
          Top := i * 20;
          Parent := self;
          text:=inttostr(i);
        end;
      end;
    end;
    d6上的这例子可以。
      

  6.   

    agree  DreamStrat(梦启动的摇篮…) 
      

  7.   

    for i := 0 to Form2.ComponentCount -1 do
      begin
        if Form2.Components[i] is TEdit then
          (Form2.Components[i] as TEdit).Text := 'aaaaa';
      end;
    这样写就OK了