Talk:VirtualTreeview Example for Lazarus

From Free Pascal wiki
Jump to navigationJump to search

Better to illustrate this examples with screenshots.

i have made some screenshots but in french version here

http://wiki.lazarus.freepascal.org/VirtualTreeview_Example_for_Lazarus/fr

My two coins ...

Thank you very much for this Tut, it helped me a lot with VirtualTreeview. These are my annotations:

- Is it really necessary to write custom handlers for onFocusChanged and onChange? In the tutorial they both contain a "VST.Refresh". It seems that the tree refreshes just fine without those two handlers, they seem superfluous.

- I found it confusing that you choose to pick the same class name "TStringEditLink" for your combo box sample, because this clashes with the original class name for the default string editor which is already contained in the tree code. A classname like TComboEditLink would, in my opinion, have made things clearer. There is a practical reason as well: if you overwrite TStringEditLink like in your sample, you overwrite the edit class for all nodes and columns. It is, however, quite common to use different editors for different columns, like so

 procedure TForm1.VSTCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode;
   Column: TColumnIndex; out EditLink: IVTEditLink);
 
 begin
   EditLink := NIL;
   case Column of
     1: EditLink:=TStringEditLink.Create;   // for clarity, is default anyway
     2: EditLink:=TComboEditLink.Create;
   end;
 end;

This combination will use the default string editor for column 1 and the combobox editor for column 2. Note that - quite unintuitively - column 1 and 3 can still be edited, using the TStringEditLink default handler, because that's what the authors of VirtualTreeView have coded in case EditLink returns NIL. If one does not want the other columns to be editable he must handle the onEditing event:

 procedure TForm1.VSTEditing(Sender: TBaseVirtualTree; Node: PVirtualNode;
   Column: TColumnIndex; var Allowed: Boolean);
 
 begin
   Allowed := Column in [1,2];
 end;

This disables editability for column 0 and 3.

Armin