如何迭代到 TTabSheet 中的组件

How to iterate into components inside a TTabSheet

我正在尝试在 TTabsheet 内的所有组件之间进行迭代。问题是,在此选项卡内只有一个备忘录和一个编辑,但我的代码在所有形式的组件之间迭代。我错过了什么?

var i : integer;
begin
with PageControl1.ActivePage do 
 for i := 0 to componentcount-1 do
   begin
   // componentcount should be 2, but actually is 95
   components[i].doSomething;
   end;
end;

我有过这样的事情,其中​​单击按钮导致代码遍历页面控件上的选项卡上的所有控件,使用组件数组。后来我将其更改为以下内容,它使用给定标签表的控件数组。

procedure TShowDocsByRank.CleanBtnClick(Sender: TObject);
var
 i: integer;

begin
 for i:= 0 to tabsheet1.controlcount - 1 do
  if tabsheet1.controls[i] is TLabeledEdit
   then TLabeledEdit (tabsheet1.controls[i]).text:= ''
  else if tabsheet1.controls[i] is TComboBox
   then TComboBox (tabsheet1.controls[i]).text:= '-';
end;

也许 'with' 可以做点什么。您真的无法判断 'componentcount' 的 return 值是多少(甚至 return 表单本身的组件数量?)。