界面上放了n个edit,n由1...n。edit1,edit2.....我要用一个循环从数组里赋值给对应的edit,应该怎么做?

解决方案 »

  1.   


    for I :=0 to count(数组) - 1 do 
    begin 
      case I of 
        0:begin
          edit1.text='';
        end;
        1:begin
          edit2.text='';
        end;
       ......
       end;
    end;
      

  2.   

     我本身還要做好EDIT與數組做好對應才行。 
     
     for i := 0 to Component.Count -1 do 
     begin
      if Component[i] is TEdit then begin
        // 再判斷下他的TAG
        if TEDit(Components[i]).tag = 99 then TEDit(Components[i]).text := fields[99].asString;
      end;
     end;
     
      

  3.   

     我本身還要做好EDIT與數組做好對應才行。 
     
     for i := 0 to Component.Count -1 do 
     begin
      if Component[i] is TEdit then begin
        // 再判斷下他的TAG
        if TEDit(Components[i]).tag = 99 then TEDit(Components[i]).text := fields[99].asString;
      end;
     end;
     
      

  4.   

    uses TypInfo;var
      PropInfo: PPropInfo;  // 要使用 TypInfo 单元
      count,i,k: integer;
      con:TComponent;
    begin
      count := 数组长度;
      for i := 0 to count - 1 do
      begin
        con := FindComponent('edit'+IntToStr(i+1));
        if con = nil then
          Exit;
        PropInfo := GetPropInfo(con.ClassInfo, 'Text');
        if Assigned(PropInfo)   then
            SetStrProp(con, PropInfo, '第'+IntToStr(i+1)+'个');
      end;
    end;