[Lazarus] TTreenode.data

Richard Mace richard.mace at gmail.com
Thu Sep 12 07:39:55 CEST 2013


On 11 September 2013 10:19, Graeme Geldenhuys <graeme at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130912/796637dd/attachment-0003.html>


More information about the Lazarus mailing list