Board index » delphi » Subclassing TTreeNode, TTreeNodes, TTreeView

Subclassing TTreeNode, TTreeNodes, TTreeView

Hello,

I want to extend the TTreeNode with some features (i. e. bold text) and want to
subclass it. Then I want to inherited TTreeNodes and TCustomTreeView to use the
new TTreeNode and give it all to my new treeview MyTreeView. I tried the whole
day to bring the thing to work but it doesn't. Has anybody an example how to
do?

Thanks

Stefan Westner

 

Re:Subclassing TTreeNode, TTreeNodes, TTreeView


Quote
Stefan Westner wrote:

> Hello,

> I want to extend the TTreeNode with some features (i. e. bold text) and want to
> subclass it. Then I want to inherited TTreeNodes and TCustomTreeView to use the
> new TTreeNode and give it all to my new treeview MyTreeView. I tried the whole
> day to bring the thing to work but it doesn't. Has anybody an example how to
> do?

> Thanks

> Stefan Westner

Try this:

  TNodeState = (nsCut, nsDropHilited, nsFocused, nsSelected, nsExpanded,
nsBold);

  TTreeNode = class(TPersistent)
  private
    function GetBold: Boolean;
    procedure SetBold(Value: Boolean);
  public
    property Bold: Boolean read GetBold write SetBold;
  end;

implementation

function TTreeNode.GetState(NodeState: TNodeState): Boolean;
var
  Item: TTVItem;
begin
  Result := False;
  with Item do
  begin
    mask := TVIF_STATE;
    hItem := ItemId;
    if TreeView_GetItem(Handle, Item) then
      case NodeState of
        nsCut: Result := (state and TVIS_CUT) <> 0;
        nsFocused: Result := (state and TVIS_FOCUSED) <> 0;
        nsSelected: Result := (state and TVIS_SELECTED) <> 0;
        nsExpanded: Result := (state and TVIS_EXPANDED) <> 0;
        nsDropHilited: Result := (state and TVIS_DROPHILITED) <> 0;
        nsBold: Result := (state and TVIS_BOLD) <> 0;
      end;
  end;
end;

procedure TTreeNode.SetBold(Value: Boolean);
var
  Item: TTVItem;
  Template: Integer;
begin
  if Value then Template := -1
  else Template := 0;
  with Item do
  begin
    mask := TVIF_STATE;
    hItem := ItemId;
    stateMask := TVIS_BOLD;
    state := stateMask and Template;
  end;
  TreeView_SetItem(Handle, Item);
end;

function TTreeNode.GetBold: Boolean;
begin
  Result := GetState(nsBold);
end;
--
--------------------------------------------------------------
 H?kon Eines, System Developer, Finale Systemer as
 Voice : + 47  77 61 55 60
 Fax   : + 47  77 68 76 44                         ||||||
 E-Mail: Haakon.Ei...@finale.no                    (.)(.)
------------------------------------------------ooO-(_)-Ooo---

Other Threads