打印本文 打印本文 关闭窗口 关闭窗口
Delphi的组件读写机制(三)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2346  更新时间:2009/4/23 18:37:52  文章录入:mintao  责任编辑:mintao
begin

  ……

    if not IgnoreChildren then

      try

        if (FAncestor <> nil) and (FAncestor is TComponent) then

        begin

          if (FAncestor is TComponent) and (csInline in TComponent(FAncestor).ComponentState) then

            FRootAncestor := TComponent(FAncestor);

          FAncestorList := TList.Create;

          TComponent(FAncestor).GetChildren(AddAncestor, FRootAncestor);

        end;

        if csInline in Instance.ComponentState then

          FRoot := Instance;

        Instance.GetChildren(WriteComponent, FRoot);

      finally

        FAncestorList.Free;

      end;

end;

       IgnoreChildren属性使一个Writer对象存储组件时可以不存储该组件拥有的子组件。如果IgnoreChildren属性为True,则Writer对象存储组件时不存它拥有的子组件。否则就要存储子组件。

        Instance.GetChildren(WriteComponent, FRoot);

       这是写子组件的最关键的一句,它把WriteComponent方法作为回调函数,按照深度优先遍历树的原则,如果根组件FRoot存在子组件,则用WriteComponent来保存它的子组件。这样我们在DFM文件中看到的是树状的组件结构。

 

上一页  [1] [2] [3] [4] 

打印本文 打印本文 关闭窗口 关闭窗口