Solved

How to use one form, do display a lot of content ?

Posted on 2004-09-24
20
270 Views
Last Modified: 2010-04-05
Hello, i am writing an application, the main form is separated on two parts. On the left there is a treeview, and on the right side i must show different content for every treeview item when it's clicked. I have over 1300 TreeView items. The content is buttons, memos editboxes and etc.. what is the best way to do it ?
0
Comment
Question by:bbh2k3
  • 8
  • 6
  • 2
  • +4
20 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12149404
May be you should use a TTabbedNotebook on the right side of your form. This way you may show the content on many Tabs and every Tab will use the whole width of the right side ....
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12149409
Or TPageControl with many TTabSheets ....
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12149484
esoftbg, we have another case of "fools seldom differ" - I had started on such an approach about an hour ago but dropped it (more pressing issues).

The suggestion I have is to think of the application as a book with pages and a table of contents or index. The TreeView provides a location within the "book" of it's particular component, which would be on any one "page".

With a small number of items, one page would suffice but it sounds like that is not the case here, so a multi-page TPageControl is a good idea.

When the TreeList is populated, a decision must be made about which page (TTabSheet) upon which to place it's information (sounds like they are all of type TControl). On selection of an item in the treelist (click event), the selected node will identify the page and the control. Best to start then, by defining a descendant of TTreeListNode.

Here's as far as I got before dropping the work:

unit uQ_21144649;
{==============================================================================}
interface
{==============================================================================}
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls;
{==============================================================================}
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Splitter1: TSplitter;
    Panel2: TPanel;
    TreeView1: TTreeView;
    PageControl1: TPageControl;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
{==============================================================================}
  TMyTreeNodeItem = class(TTreeNode)
  private
    { Private declarations }
    fPageNumber  : Integer;      // The object's page in the TPageControl
    fTabSheet    : TTabSheet;
    fControlType : TClass;
    fControl     : TControl;     // The object's control in the TPageControl
    function  GetControlType : TClass;
    procedure SetControlType(aClass : TClass);
    function  GetControl : TControl;
    procedure SetControl(aControl : TControl);
  public
    { public declarations }
    constructor Create (anOwner : TObject);
    destructor  Destroy; override;
  published
    { published declarations }
    property PageNumber : Integer Read fPageNumber Write fPageNumber;
    property ControlType : TClass Read  GetControlType
                                  Write SetControlType;
    property Control     : TControl Read  GetControl
                                    Write SetControl;
  end;
{==============================================================================}
var
  Form1: TForm1;
  treeRoot : TMyTreeNodeItem;   // Anchor for the TTreeList
{==============================================================================}
implementation

{$R *.dfm}
{==============================================================================}
constructor TMyTreeNodeItem.Create(anOwner : TObject);
BEGIN
  inherited Create(Form1.TreeView1.Items);
  fTabSheet := TTabSheet.Create(fControl);
  fTabSheet.PageControl := Form1.PageControl1;
  fTabSheet.Caption := 'Item';
  fPageNumber := fTabSheet.TabIndex;
  fControlType := TObject;
  fControl := nil;
END {Create};
{==============================================================================}
destructor TMyTreeNodeItem.Destroy;
BEGIN
  inherited Destroy;
END {Destroy};
{==============================================================================}
FUNCTION TMyTreeNodeItem.GetControlType : TClass;
BEGIN
  GetControlType := Self.fControlType;
END {GetControlType};
{==============================================================================}
PROCEDURE TMyTreeNodeItem.SetControlType(aClass : TClass);
BEGIN
  Self.fControlType := aClass;
END {GetControlType};
{==============================================================================}
FUNCTION TMyTreeNodeItem.GetControl : TControl;
BEGIN
  GetControl := Self.fControl;
END {GetControl};
{==============================================================================}
PROCEDURE TMyTreeNodeItem.SetControl(aControl : TControl);
BEGIN
  Self.fControl := aControl;
END {GetControl};
{==============================================================================}
procedure TForm1.FormCreate(Sender: TObject);
begin
  treeRoot := TMyTreeNodeItem.Create(Form1);
end;
{==============================================================================}

end.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12149640
TPageControl (Win32 tab)

The Page control components will give you pages, you can separate you controls as General, Additional, etc... and put each group on different page

When you click on specific item from the TreeView, you display the page you need...
0
 
LVL 17

Expert Comment

by:mokule
ID: 12149660
Hi,
Another possibility is to create and destroy appropriate set of controls for each tree view item at runtime.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12149678
mokule, don't we need to distinguish between the lifetime of an object and its location? It seems to me that you have addressed the former while the rest of us, so far, have assumed a relatively static lifetime and concentrated on location. The answer is probably a fusion of the two. Most certainly, I have seen no need to assume that the lifetime of the display component of the treelist items should be anything but dynamic. I guess it depends on whether their content must be persistent.
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 12149683
He said that he has over than 1300 Treeview items! This means A TPageCOntrol with too much TTabsheets. What happens to the memory after loading so much objects both?
I'd use Frames to load just the desired on a panel. I know that the topic is 'use one form', but this is (in my opinion) the more stable and less memory expensive method to do this...

e.g.

unit TLForm;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    TreeView1: TTreeView;
    procedure FormCreate(Sender: TObject);
    procedure TreeView1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    procedure ShowFrame (FrameName: string);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

type
  TFrameClass = class of TFrame;

procedure TForm1.ShowFrame(FrameName: string);
var
  Frame: TFrame;
  FrameClass: TFrameClass;
begin
  Frame := FindComponent (FrameName + '1') as TFrame;
  if not Assigned (Frame) then
  begin
    FrameClass := TFrameClass (FindClass ('T' + FrameName));
    Frame := FrameClass.Create (Self);
    Frame.Parent := Panel2;
    Frame.Visible := True;
    Frame.Name := FrameName + '1';
  end;
  Frame.BringToFront;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
showframe('Frame1');
end;

procedure TForm1.TreeView1DblClick(Sender: TObject);
begin
ShowFrame(TReeView1.Selected.Text);
end;

end.

unit Frame2u;

interface

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

type
  TFrame2 = class(TFrame)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    Button1: TButton;
    Button2: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.DFM}

initialization
  RegisterClass (TFrame2);

end.

Download an example Project here: www.afsoftware.it\ExEx\Q_21144649.zip

0
 
LVL 7

Expert Comment

by:sftweng
ID: 12149703
Feruccio68, I'll have a look at your example after I get some sleep :-). I think you've misunderstood, though, the proposal concerning a TPageControl. One would not create a new page (TTabSheet) for each treelist node, but merely place it onto one of the pages. You definition of static (define-time) elements for the frame appears to me to be less flexible than just placing a TControl onto a TTabSheet at runtime, though I may have misunderstood your proposal at first glance.

One parting comment before I try to sleep a bit - the talent we have assembled here is wonderful. I'm confident that with cooperation, we'll find the best solution for bbh2k3. Perhaps it's time to hear more specifications from the questioner, or at least reactions to what has been proposed.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12149704
BTW, my browser says that  www.afsoftware.it\ExEx\Q_21144649.zip
 cannot be found.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12149713
sftweng, yes, rereading the Q. maybe i've misunderstood it.

Btw i agree about the cooperation :))

--> BTW, my browser says that ....
Strange, for me it's working....try with a 'Save object as....'

F68 ;-)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 7

Expert Comment

by:sftweng
ID: 12149722
Apologies - my local browser file association must be broken. When I cut-and-paset the URL into IEExploerer and Mozilla Firefox address windows, it downloads nicely, just not when I click on the URL in your message.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12149762
pieces of the original question:

> .... and on the right side i must show different content for every treeview item when it's clicked. .... The content is buttons, memos editboxes and etc.. what is the best way to do it ?

So, the question is NOT ABOUT 1300 TreeView items on the right side of the form (because they are on the left side).
The question is about the buttons, memos editboxes and etc.. In this case the best way to be placed the content is TPageControl (or TTabbedNotebook) as I posted here more than 3 hours ago ....
 
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12150097
esoftbg, i am I correct following review of your 02:16 comment that you envision placing the components at design time on the various TTabSheets and then creating the treelist dynamically at run time by navigating through the sheets or, possibly, by hard-coding their addition to the treelist?

In any case, bbh2k3 should probably tell us a little more about how the raw data elements are defined - perhaps they are driven by some external file definition (e.g., an XML file). Perhaps the choice of component is described only on paper and a design-time placement would be appropriate. However, if their TControl type can be determined dynamically from some context (perhaps by parsing an input file), then creating both the treeview and the page control at runtime would be appropriate.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12150273
Hi sftweng,
My view point about this question was very simply: "How to use one form, do display a lot of content ?"
I said: TPageControl (or TTabbedNotebook) to obtain more area for placing components (buttons, memos editboxes and etc..) on different Sheets on the right side of the same Form. Example: on the TabSheet1 have placed 3 Buttons and 2 Memos, on the TabSheet2 have placed 4 Buttons and 6 Edits and so on .... I don't think bbh2k3 did ask about the:
>  creating the treelist dynamically at run time by navigating through the sheets or, possibly, by hard-coding their addition to the treelist?
For me this question is about to how to increase the useable area to place known count of components.
And about my 02:16 comment, I posted it at 12:16 Bulgarian time ;-))
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12150301
sftweng, I guess you are located 2 hours on east (Iran, Russia) or 10 hours on west (America [North, South]) from my location .... ;-))
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12150632
Canada
0
 
LVL 9

Expert Comment

by:ezraa
ID: 12155949
I have faced a similar problem and ended up with a database application. I'll describe it in short:
On the left side is a treeview of "Subjects". Clicking on a branch in the subjects tree loads a flex-grid of "Fields" on the right the side. I'm using ElTree as my flex grid and I'm also placing on top of it other components to suite my needs (For example a combo-tree or images). The whole "database" is very generic so I built another application that is the database builder - that is used to define the Subjects, Fields, Custom Types and so forth making it very easy to add pages. To store the information I have a database with 4 main tables: Subjects, Fields, Types and Data. The Types table describes the type of component used for a Field. The Data table holds the actual information entered by the user into the Fields.
0
 

Author Comment

by:bbh2k3
ID: 12171347
Database will not work for me ... i am sure ..
Will the TabbedNotebook work for me ? ... 1300 pages ?
what do u think ?
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12171557
You don't need 1300 pages, you could put several components on each page. Maybeyou only need 13 pages. It dependes what kind of components they are and how many you can fit on each page.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12175022
Hi bbh2k3,
download an example from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21144649.zip
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now