for i:=1 to N do
begin
    Components.FindComponent('button'+inttostr(i)).caption='';
end;

解决方案 »

  1.   


    for i:=0 to componentCount-1 do
      if  (Components[i] is TButton) then 
               (Components[i] as TButton).Caption:='标题';
      

  2.   

    其实FindComponent也是在Components找,效率到不高
      

  3.   

    用peterguo的和myxfang的都一样!
      

  4.   

    peterguo的效率更高,因为只遍历了一次,
    而用FindComponent则每一次都会从头找。
      

  5.   

    请问,component 包含在哪个单元里呢?
    使用时要在uses中添加什么?
      

  6.   

    To : gz_xjf(thinker) 
        什么意思?
      

  7.   

    给分吧,peterguo(peterguo)讲得已经很清楚了
      

  8.   

    可是编译出错,可能是用 component  要在uses中加入哪个单元。
      

  9.   

    就是你的鼠标移到相应的函数上面同时按住Ctrl,这是看到函数下面有下划线
    点一下就进到相应的声明处,但前提是你得uses这个包含这个函数的文件
    另外Components等你不需要uses,直接用就行,应为Components都是TForm继承来的
      

  10.   

    可是编译时会停在 components 上说:Undeclared identifier: 'components' 
      

  11.   

    Classes Uses了吗,默认都有的,
      

  12.   

    会不会你的Delphi有问题?重装试试
      

  13.   

    如果加上'Self.'还出错的话,那有可能是你用到Components的函数或过程没有写成:
    procedure TForm1.MyFunc;
    而是写成了:
    procedure MyFunc;
      

  14.   

    peterguo(peterguo) 他已经说得很清楚了
      

  15.   

    在前面加个FORM1就可以了,Components是TForm继承来的。for i:=0 to Form1.ComponentCount-1 do
      if  (Form1.Components[i] is TButton) then 
              (Form1.Components[i] as TButton).Caption:='标题';