'在DELPHI中,怎么遍历相同的控件?
'如,在DELPHI中,设置3个EDIT控件,edit1,edit2,edit3
'请问怎么遍历在窗体上的这三个控件?'*****************************************
'能象VB6这样遍历?或用其它的方法?
Private Sub Command1_Click()
'设置了3个Text1控件数组
Dim txt As TextBoxFor Each txt In Text1
    Debug.Print txt.Name, txt.Index
NextEnd Sub

解决方案 »

  1.   

    for i:=0 to control.count-1 do
     if Control[i] is TEdit then
      do somthing;
      

  2.   

    上面有点笔误
    以下是正确的
    procedure TForm1.Button1Click(Sender: TObject);
    var
    i:integer;
    begin
         for i:=0 to controlCount-1 do
         if controls[i] is TEdit then
           (controls[i] as TEdit).Text:=IntTostr(i);
    end;
      

  3.   

    for i:=0 to self.ComponentCount-1 do
     if Self.Components[i] is TEdit then
        MessageDlg('是的',mtInformation,[mbOk],0); 
      

  4.   

    楼上的方法有缺陷:如果一个控件是动态创建的,并且它的Owner不是你的窗体,就找不到。
    最好使用TComponent的Components和ComponentCount属性进行递归遍历
      

  5.   

    for i:=0 to controlCount-1 do
         if controls[i] is TEdit then
           (controls[i] as TEdit).Text:=IntTostr(i);
      

  6.   

    也就是这样了.可以用Form1.Componts[i]