[Lazarus] TTreenode.data

Antonio Fortuny a.fortuny at sitasoftware.lu
Fri Sep 13 09:37:46 CEST 2013


Le 13/09/2013 07:48, Richard Mace a écrit :
> OK, I now have this code:
> with 
> tvMain.Items.AddChildObject(tvMain.Selected,IntToStr(fUserList.Items[I].Id),Pointer(fUserList.Items[I].Id)) 
> do
>
> and this:
> procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode);
> begin
>   if Assigned(Node.Data) then
> ShowMessage('Node ' + IntToStr(PtrInt(Node.Data)));
> end;
>
> And I am now getting an exception when my app run?
>
> Richard
>
Details are missing about your implementation: Lzarus & FPC, OS, etc. 
I've made a little test on Win32 and Linux_X64, Lazarus 1.0.12
I added some nodes to the TTreeView like this:

var
   SData: Integer=179;

procedure TFrmMain.BtnTestTvClick(Sender: TObject);
var
   wNode: TTreeNode = nil;
   s: String;
begin
   Inc(SData);
   wNode := Ttv.Items.AddChildObject(nil, 'node new', Pointer(SData));
   s := Format('node %s data:%d', [wNode.Text, PtrInt(wNode.Data)]);
   MessageDlg('Titre', s, mtInformation, [mbOK], 0, mbOK);
end;

The I added an event to Ttv.OnChange event like that:
procedure TFrmMain.TtvChange(Sender: TObject; Node: TTreeNode);
var
   wData: Integer;
begin
   if Assigned(Node) then begin
     wData := PtrInt(Node.Data);
     MessageDlg('Titre',Format('data for "%s" %d', [Node.Text, wData]), 
mtInformation, [mbOK], 0, mbOK);
   end;
end;

I get a new node on every BtnTestTvClick and a value starting from 180 
on every OnChange event
On both platforms.

Antonio.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130913/5f6d4771/attachment-0003.html>


More information about the Lazarus mailing list