首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

有一个有关问题,百思不得其解

2012-02-12 
有一个问题,百思不得其解请各位看一下下面这段代码,调试的时候发现程序根本就执行for循环,为什么会这样的?

有一个问题,百思不得其解
请各位看一下下面这段代码,调试的时候发现程序根本就执行for循环,为什么会这样的?是不是这样写有问题?
    btnCount   :=   1;
    with   TButton.Create(Self)   do
    begin
        for   I   :=   0   to   ComponentCount-1   do
            if   Components[I]   is   TButton   then
                Inc(btnCount);
        Parent   :=   Form1;
        Name   :=   'Button '   +   inttostr(btnCount);
        Top   :=   Button1.Top   +   10;
        Left   :=   Button1.Left   +   10;
        DragMode   :=   dmAutomatic;
    end;

[解决办法]
呵呵,当然啦TButton.Create(Self)根本就没有子控件
[解决办法]
for I := 0 to Self.ComponentCount-1 do
if Self.Components[I] is TButton then
Inc(btnCount);

热点排行