<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial">On 11 September 2013 10:19, Graeme Geldenhuys </span><span dir="ltr" style="font-family:arial"><<a href="mailto:graeme@geldenhuys.co.uk" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=graeme@geldenhuys.co.uk&cc=&bcc=&su=&body=','_blank');return false;">graeme@geldenhuys.co.uk</a>></span><span style="font-family:arial"> wrote:</span><br>

</div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">

On 2013-09-11 06:51, Richard Mace wrote:<br>
> Can anyone give me an example of adding and retrieving an integer value to<br>
> a TTreenode via it's data property please?<br>
<br>
</div>The Data property holds a pointer value, so don't assign an Integer<br>
directly. Rather define a Record structure (or a Class) that holds the<br>
data you want (in your case an Integer field), then assign the pointer<br>
to the record structure to the Treenode.Data property.<br>
<br>
There is an example in the LCL documentation:<br>
<br>
  <a href="http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttreenode.data.html" target="_blank">http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttreenode.data.html</a></blockquote><div><br></div><div class="gmail_default">

<font face="arial, helvetica, sans-serif">OK, thanks for everyone's input. I have re-written it with the following, but ShowMessage still isn't display the correct User.Id</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">For clarification fUserList is a TObjectList</font></div>

<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif">with tvMain.Items.AddChild(tvMain.Selected,IntToStr(fUserList.Items[I].Id)) do</span><br>

</div><div class="gmail_default"><font face="arial, helvetica, sans-serif">  begin</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">    Data := fUserList.Items[I];</font></div><div class="gmail_default">

<font face="arial, helvetica, sans-serif">    ImageIndex := 2;</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">  end;</font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">

</div><div class="gmail_default"><div class="gmail_default"><font face="arial, helvetica, sans-serif">procedure TfrmMain.tvMainSelectionChanged(Sender: TObject);</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">begin</font></div>

<div class="gmail_default"><font face="arial, helvetica, sans-serif">  if Assigned(TTreeNode(Sender).Data) then</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">    ShowMessage('Node ' + IntToStr(TUser(TTreeNode(Sender).Data).Id));</font></div>

<div class="gmail_default"><font face="arial, helvetica, sans-serif">end;</font></div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">I'm obviously doing something a bit daft, but can't work out what?</div>

<div style="font-family:arial,helvetica,sans-serif">Any input would be greatly received.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Thanks</div>
<div style="font-family:arial,helvetica,sans-serif">
<br></div><div style="font-family:arial,helvetica,sans-serif">Richard</div></div></div></div></div>