Re:Sub-classing TTreeNode for use with TCustomTreeView
In article <d36116ef.0209081618.726b6...@posting.google.com>,
Quote
jrick...@unisystems.biz (Jeremy Rickard) writes:
>I'm working on a tree object browser, and thought that the best way to
>encapsulate the different actions for nodes in the tree would be to
>create subclasses for each of the different types of nodes. In
>practice I'm finding this does not work since TCustomTreeView seems to
>regard every node as a bog standard TTreeNode.
Do you ...
1 Code a descendant of TTreeNode encapsulating your desired changes to the tree
node.
2 Code a descendant (if necessary) of TTreeView encapsulating the differences
(if any) you need to cope with the TTreeNode descendant.
3 Create the TTreeview by calling MyTreeView :=
TMyTreeview.Create(TMyTreeNode);
The following was a note I had found on changing TTreeNode characteristics ...
"Adding Extra Properties to TreeView Nodes
unit mytreeview;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, CommCtrl;
type
TMyTreeNode = class(TTreeNode)
private
fDataString: String;
public
constructor Create(AOwner: TTreeNodes);
property DataString: string read fDataString write fDataString;
end;
TMyTreeview = class(TTreeView)
public
function CreateNode: TTreeNode; override;
end;
procedure Register;
implementation
function TMyTreeView.CreateNode: TTreeNode;
begin
Result := TMyTreeNode.Create(Items);
end;
constructor TMyTreeNode.Create(AOwner: TTreeNodes);
begin
inherited Create(AOwner);
fDataString := '';
end;
procedure Register;
begin
RegisterComponents('Samples', [TMyTreeView]);
end;
end."
Alan Lloyd
alangll...@aol.com