Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open Delphi form in Treeview

Posted on 2004-04-29
9
Medium Priority
?
300 Views
Last Modified: 2010-04-05
I wish to have a form with a button & a file open dialog box. When the button is clicked a form can be chosen using the open dialog box & the components listed in a treeview with the correct parent child relationships between the forms components.

Any idea's ?

Thanks
Paul.
0
Comment
Question by:pr_wainwright
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10946909

  for counter := 0 to Form1.ComponentCount-1 do
    begin
      ComponentName := (Form1.Components[counter] as TComponent).Name;
      OwnerName := (Form1.Components[counter].Owner as TComponent).Name;
      // add to tree view ...
    end;

  but I don't have ide how you will open the DFM cause it is not in readable format ....
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 10947807
Ivanov G,
 I think from Delphi 4 or 5 onwards, can't remember which form files are stored as text files.

Regards
Paul.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10947945

   Yep, I checked it on D7 - it is text file ... but parsing the text is not so easy...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:pritaeas
ID: 10948141
Actually, you can read the form's text file into a stream and use ObjectTextToBinary to convert that text into an actual form. Then you can use the code above, to loop through all the components and display them.
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 10951033
pritaeas,
            I can't seem to get your idea to work using ObjectTextToBinary. Do you have a source code example to help me along ?.

Thanks
Paul.
0
 
LVL 6

Expert Comment

by:pritaeas
ID: 10968775
Sorry, I can't find my original source anymore. I'll try to recreate an example, then I'll get back to you.
0
 
LVL 6

Expert Comment

by:pritaeas
ID: 10972872
Hi. Tried to recreate my idea, but it doesn't work. This comes because the type of form I want to create is not registered at that time.

However, looking throught the .dfm file I noticed that every 'object' is as text inside the parent object. Each nesting indents with 2 spaces. This should be enough to recreate a tree. Just load the .dfm into a stringlist. Delete all lines NOT beginning with 'object' (ignore leading spaces). Then build a tree from that textfile.

hth, pritaeas
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10975141
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    CheckBox1: TCheckBox;
    Button2: TButton;
    Panel1: TPanel;
    Memo1: TMemo;
    TreeView1: TTreeView;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure AddToList(ParentName: String; Childs: TStringList);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure EnumChilds (Parent : TComponent; var ChildList : TStringList);
var
  counter     : Integer;
  name        : String;
begin
  if Parent.ComponentCount > 0 then
    for counter := 0 to Parent.ComponentCount - 1 do
      begin
        name := (Parent.Components[counter] as TComponent).Name;
        ChildList.Add(name);
      end;
  Form1.AddToList(Parent.Name, ChildList);
  ChildList.Clear;
end;

procedure TForm1.AddToList(ParentName: String; Childs: TStringList);
var
  childnode : TTreeNode;
  i : integer;
begin
  childnode := TTreeNode.Create(TreeView1.items);
  TreeView1.Items.AddChild(childnode, parentName);
  for i := 0 to childs.count - 1 do
    TreeView1.Items.AddChild(childnode, childs[i]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  List : TStringList;
begin
  List := TStringList.Create;
  EnumChilds(Self, List);
end;

end.
0
 
LVL 6

Accepted Solution

by:
pritaeas earned 500 total points
ID: 11045079
Hi Paul,

sorry for the very late reply, but I hope you can use it. Download the demo-project from my website at:

http://pritaeas.net/demo_projects/dfm2tree.zip

hth, Hans 'pritaeas' Pollaerts
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question