e40到e48的控件均存在且有値for i:=40 to 48 do
    begin
      sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
    end;为什么执行出错???

解决方案 »

  1.   

    控件名是一种特殊的字符串 不能用普通的方法使用
    对于你的问题 可以有中解决思路:
    将所有EDIT放到一个容器里,如Panel 然后这样做
    var
      i,s: integer;
    begin
      for i:=0 to Panel.Controls.ControlCount-1 do
        if Panel.Controls[i] is TEdit then
          s:=s+StrToInt(TEdit(Panel.Controls[i]).Text);
    end;
      

  2.   

    var
      I,Sum: Integer;
      tfComponent: TComponent;
    begin
      Sum := 0;
      for I := 40 to 48 do
      begin
        tfComponent := FindComponent('e' + IntToStr(I));
        if tfComponent <> nil then
          Inc(Sum, StrToIntDef(Trim(TEdit(tfComponent).Text), 0));
      end;
    end;检查e40到e48的控件名字的第一个子目是“e”还是“E”—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————