Recent

Author Topic: TTreeView.OnCustomCreateItem, always NIL for each item created elsewhere?  (Read 167 times)

jamie

  • Hero Member
  • *****
  • Posts: 3507

 I thought this would be a good idea to use this event so that when loading from resource or some other sources it would give me the chance to make changes during the creation process..

  It appears that if I load from resource (lfm) designed info or manual add one via the normal channels this event gets called but always has NIL object.

  Drop a TreeView on the form, add a couple of items and implement the OnCustomCreateItem event.
  With mine Lazarus as the items are being created and populating the Tree this event gets called but it has a nil pointer..

 Can someone explain to me where I am going wrong using this event ?

The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 2902
  • POKE 54296,15
    • Eye-Candy Controls
This is code from treeview.inc:
Code: Pascal  [Select][+][-]
  1. function TCustomTreeView.CreateNode: TTreeNode;
  2. var
  3.   NewNodeClass: TTreeNodeClass;
  4. begin
  5.   Result := nil;
  6.   if Assigned(FOnCustomCreateItem) then
  7.     FOnCustomCreateItem(Self, Result);
  8.   if Result = nil then
  9.   begin
  10.     NewNodeClass:=TTreeNode;
  11.     DoCreateNodeClass(NewNodeClass);
  12.     Result := NewNodeClass.Create(Items);
  13.   end;
  14. end;
so it gives you a chance to create your own node. If you don't create any, it creates node itself.

(I just don't see use-case for this method but I believe someone had reason to implement it.)
Lazarus 2.1.0 r63881 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 3507
Hmm
Quote
(I just don't see use-case for this method but I believe someone had reason to implement it.)
My sentiments exactly ..

 however, it looks like I could specify a different class If I wanted too, much like the TCollection does with the using the TCollectionItem.

 Ok, I'll need to think about this one.. Thanks.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018