用程序打印Object Tree

时间:2010-03-07 14:01:32  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:/>n, pn, pcn:    string;node, nodeNew: TTreeNode;hasUndo:       boolean;begin  // todo: generate treetvSt.Items.Clear;  tvSt.Items.Add(nil, FormWindow.Name);  hasUndo := True;  while hasUndo do  begi...
  正文:

procedure TFormObjTree.GenerateTree;
var
i:             integer;
comp:          TComponent;
n, pn, pcn:    string;
node, nodeNew: TTreeNode;
hasUndo:       boolean;
begin
  // todo: generate tree
tvSt.Items.Clear;
  tvSt.Items.Add(nil, FormWindow.Name);
  hasUndo := True;
  while hasUndo do
  begin
    hasUndo := False;
    for i := 0 to FormWindow.ComponentCount - 1 do
    begin
      comp := FormWindow.Components[i];
      n    := comp.Name;
      if comp is TControl then
      begin
        pn := TControl(comp).Parent.Name;
        pcn := TControl(comp).Parent.ClassName;
      end
      else
      begin
        pn := comp.GetParentComponent.Name;
        pcn := comp.GetParentComponent.ClassName;
      end;
      node := NodeExist(pn);
      if node = nil then
      begin
        hasUndo := True;
        Continue;
      end;
      nodeNew := NodeExist(n);
      if nodeNew <> nil then
      Continue;
      tvSt.Items.AddChild(node, n);
    end;
  end;
  for i := 0 to tvSt.Items.Count - 1 do
  begin
    if tvSt.Items[i].Parent = nil then
    begin
      tvSt.Items[i].ImageIndex    := 2;
      tvSt.Items[i].SelectedIndex := 2;
    end
    else
    begin
      if tvSt.Items.Item[i].HasChildren then
      begin
        tvSt.Items.Item[i].ImageIndex    := 1;
        tvSt.Items.Item[i].SelectedIndex := 1;
      end
      else
      begin
        tvSt.Items.Item[i].ImageIndex    := 0;
        tvSt.Items.Item[i].SelectedIndex := 0;
      end;
    end;
  end;
  tvSt.FullExpand;
end;

效果:

"用程序打印Object Tree"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/13117.html


关键字:

关于《用程序打印Object Tree》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td