Re: TXMLDocument and TTreeView



Still no luck with this. I think I'll be using the alternative XML
Document component that I mentioned before unless anyone else can
suggest anything.

FWIW, here is a demo of using a custom TreeNode type to store an
interface reference - I hope it is of some help:

unit Unit1;

interface

uses
Forms, ComCtrls, Classes, Controls;

type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure TreeView1CreateNodeClass(Sender: TCustomTreeView;
var NodeClass: TTreeNodeClass);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
ComObj; // for CreateOleObject

type
TMyTreeNode = class(TTreeNode)
public
FInterface: IInterface;
destructor Destroy; override;
end;

destructor TMyTreeNode.Destroy;
begin
FInterface := nil;
inherited Destroy;
end;

procedure TForm1.TreeView1CreateNodeClass(Sender: TCustomTreeView;
var NodeClass: TTreeNodeClass);
begin
NodeClass := TMyTreeNode;
end;

procedure SetInterface(Node: TTreeNode; Intf: IInterface);
begin
(Node as TMyTreeNode).FInterface := Intf;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
V: Variant;
begin
// testing
TreeView1.Items.Add(nil, 'First');
TreeView1.Items.Add(nil, 'Second');
SetInterface(TreeView1.Items[1], CreateOleObject
('InternetExplorer.Application'));
// use late binding automation to demonstrate access to the
// saved interface as no tlb is to hand
V := (TreeView1.Items[1] as TMyTreeNode).FInterface as IDispatch;
TreeView1.Items[1].Text := V.Name;
end;

end.

and the form:

object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 293
ClientWidth = 426
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object TreeView1: TTreeView
Left = 0
Top = 0
Width = 426
Height = 293
Align = alClient
Indent = 19
TabOrder = 0
OnCreateNodeClass = TreeView1CreateNodeClass
end
end
.



Relevant Pages