[Lazarus] Adding data field to a child node in a treeview

Michael Van Canneyt michael at freepascal.org
Sat Jul 4 10:57:28 CEST 2015



On Sat, 4 Jul 2015, Susie Nicol wrote:

> Hi - me again
> 
> I have a Lazarus treeview, which I am populating from several sql queries.
> 
> I add  child nodes in this way, setting them to one of the fields returned from the query
> 
>            while Not SQLQuery1.EOF do
>           Begin
>  
>           treeview1.items.addchild(treeview1.selected, SQLQuery1.fields[0].AsString);
>  
>            SQLQuery1.Next
>           end;    
> 
> That works of course.
> 
> I want to modify the newly added node by setting its data property to another field in the loop - something like
> 
>     treeview1.SOMETHING.data := Pointer(SQLQuery1.fields[1].AsInteger);
> 
> but the problem is that I can't work out how to identify the newly-added child node.  Is it possible?

Not like this. You need to keep a reference when doing an AddChild:

Var
   N : TTreeNode;

begin
   N:=Treeview1.items.addchild(treeview1.selected, SQLQuery1.fields[0].AsString);
   N.data := Pointer(SQLQuery1.fields[1].AsInteger);
end;

Michael.


More information about the Lazarus mailing list