On 11 September 2013 10:19, Graeme Geldenhuys <gra...@geldenhuys.co.uk>wrote:
> On 2013-09-11 06:51, Richard Mace wrote: > > Can anyone give me an example of adding and retrieving an integer value > to > > a TTreenode via it's data property please? > > The Data property holds a pointer value, so don't assign an Integer > directly. Rather define a Record structure (or a Class) that holds the > data you want (in your case an Integer field), then assign the pointer > to the record structure to the Treenode.Data property. > > There is an example in the LCL documentation: > > http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttreenode.data.html OK, thanks for everyone's input. I have re-written it with the following, but ShowMessage still isn't display the correct User.Id For clarification fUserList is a TObjectList with tvMain.Items.AddChild(tvMain.Selected,IntToStr(fUserList.Items[I].Id)) do begin Data := fUserList.Items[I]; ImageIndex := 2; end; procedure TfrmMain.tvMainSelectionChanged(Sender: TObject); begin if Assigned(TTreeNode(Sender).Data) then ShowMessage('Node ' + IntToStr(TUser(TTreeNode(Sender).Data).Id)); end; I'm obviously doing something a bit daft, but can't work out what? Any input would be greatly received. Thanks Richard
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus