原先在设计期时我在Panel1上放有TButton等组件,现在想实现在程序运行期动态清除Panel1上原有的所有组件,并动态生成TMemo组件,该如何实现??请大侠们赐教!!!!

解决方案 »

  1.   

    用findcomponent遍历parent是panel1的组件,然后释放
    再生成memo,把memo的parent := panel1;
      

  2.   

    如何遍历??另外,findcomponent是函数吗?用不用在程序开头Use一下?
      

  3.   

    var i:integer;
    begin
      for i:=ComponentCount-1 downto 0 do
      if Components[i] is Tbutton then
      if (Components[i] As TButton).Parent=Panel1 then
       (Components[i] As TButton).Free;
    end;
      

  4.   

    多谢石头!!进一步,要是原来的Panel1上有不一致的component呢?如,既有TButton又有TImage,又有TEdit,那又如何实现??
      

  5.   

    var i:integer;
    begin
      for i:=ComponentCount-1 downto 0 do
      if Components[i] is Tbutton then
      if (Components[i] As TButton).Parent=Panel1 then
       (Components[i] As TButton).Free;
      if Components[i] is TImage then
      if (Components[i] As TImage).Parent=Panel1 then
       (Components[i] As TImage).Free;
      if Components[i] is TEdit then
      if (Components[i] As TEdit).Parent=Panel1 then
       (Components[i] As TEdit).Free;
    end;