不用這樣寫,可以這樣寫
for i:=1 to 6 do
begin
   if TEdit(Findcomponent('Edit'+inttostr(i))).text<>'' then
   //add youself code
end;

解决方案 »

  1.   

    建议这样写,便于以后修改代码
    function IsAllEmpty(EA: array of TEdit): Boolean;
    var I: Integer;
    begin
      Result := True;
      for I := Low(EA) to High(EA) do
        Result := Result and (Length(EA[I]) = 0);
    end;
    //sample
    if IsAllEmpty([TEdit1, TEdit2, TEdit3]) then 
    // do something
      

  2.   

    不用這樣寫,可以這樣寫 
    for i:=1 to 6 do 
    begin 
       if TEdit(Findcomponent('Edit'+inttostr(i))).text<>'' then 
    //add youself code end;
    是错误的;这样就对了;看一看 下边的如何?!
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
      emp:boolean;
    begin
       for i := 0 to form1.ComponentCount-1 do
         begin
           if form1.Components[i] is Tedit then
             if Tedit(form1.Components[i]).text='' then
             emp:=true else
             begin
               emp:=false;
               exit;
             end;
         end;
    end;