You can store the pointer of the treeview in a TList object and use the
index in the TList to access it.  The trick is to keep a handle on what each
pointer represents. This just duplicates the internals of a TForm. 

I've seen an implementation where each intance is given a unique .tag
property and the application searches through the Controls array to find the
TControl(Form.Controls[i]).tag that matches.

The simplest way (if you know the maximum number of treeviews) is to declare
all possible treeviews as variables in the unit and instantiate them as
required.  There is very little memory penalty with this as no resources are
allocated until the object is instantiated.  This does require you to test
them and free any instances in the Form.onDestroy event.

HTH

Stephen

-----Original Message-----
From: Chrissy R [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 30 November 2000 13:04
To: Multiple recipients of list delphi
Subject: [DUG]: Creating An Object At Run Time


Hi,

Thanks for you help yesterday on creating an object (TreeView) but I am
still having problems.  I can create as many objects as I want but I do not
know how to access these in code at a later stage.  I want to be able to 
insert, delete etc nodes, make the TreeView invisible and lots of other
things
but I do not know what it is called so I cannot use, for example, 

xxx.Visible := False;

I do not know what to use in place of "xxx".  The code is as follows and
there
is one form with a button and two units - all with default names.


Chrissy.


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  MyList1: TMyList;
begin
  MyList1 := TMyList.Create(Self);
  MyList1.Parent := Form1;
  MyList1.Items.AddChildFirst(nil,MyList1.Name);
  MyList1.Name := 'TreeView';
  MyList1.Visible := True;
  MyList1.Items.AddChildFirst(nil,MyList1.Name);
  MyList1.SendToBack;
end;

end.


unit Unit2;

interface

uses
  ComCtrls, Controls, Classes;

type
  TMyList = class(TCustomTreeView)
  public
    constructor Create(AOwner: TComponent);
  published
    property Items;
  end;

implementation

constructor TMyList.Create(AOwner: TComponent);
begin
  inherited Create(Owner);  // Initialize inherited parts
  Align := alLeft;
end;

end.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to