Re: [Lazarus] TTreenode.data
Le 17/09/2013 07:16, Richard Mace a écrit : Thanks Antonio, that worked fine. Goodness knows what I was originally doing! Nothing less I did when I started to play with pointers. 8-) Happy to be usefull. Antonio. Richard -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Thanks Antonio, that worked fine. Goodness knows what I was originally doing! 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. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
It is, and yes I am. :-) On 13 Sep 2013 16:01, Reinier Olislagers reinierolislag...@gmail.com wrote: On 13/09/2013 09:37, Antonio Fortuny wrote: Le 13/09/2013 07:48, Richard Mace a écrit : OK, I now have this code: Details are missing about your implementation: Lzarus FPC, OS, etc. Guessing Windows x86 - not writing a FreeSwitch control application, by any chance [1] ;) http://thread.gmane.org/gmane.comp.telephony.freeswitch.user/64508 -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Nice. Use FS a bit myself - nice to see Lazarus tooling for it appear. On 14/09/2013 08:45, Richard Mace wrote: It is, and yes I am. :-) On 13 Sep 2013 16:01, Reinier Olislagers reinierolislag...@gmail.com mailto:reinierolislag...@gmail.com wrote: On 13/09/2013 09:37, Antonio Fortuny wrote: Le 13/09/2013 07:48, Richard Mace a écrit : OK, I now have this code: Details are missing about your implementation: Lzarus FPC, OS, etc. Guessing Windows x86 - not writing a FreeSwitch control application, by any chance [1] ;) http://thread.gmane.org/gmane.comp.telephony.freeswitch.user/64508 -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On Fri, Sep 13, 2013 at 8:48 AM, Richard Mace richard.m...@gmail.com wrote: And I am now getting an exception when my app run? Use debugger to see what goes wrong. Juha -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On 13/09/2013 09:37, Antonio Fortuny wrote: Le 13/09/2013 07:48, Richard Mace a écrit : OK, I now have this code: Details are missing about your implementation: Lzarus FPC, OS, etc. Guessing Windows x86 - not writing a FreeSwitch control application, by any chance [1] ;) http://thread.gmane.org/gmane.comp.telephony.freeswitch.user/64508 -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On Thu, 12 Sep 2013 06:39:55 +0100 Richard Mace richard.m...@gmail.com wrote: [...] procedure TfrmMain.tvMainSelectionChanged(Sender: TObject); begin Sender is the tvMain. 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. Mattias -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
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 On 11 September 2013 09:24, Antonio Fortuny a.fort...@sitasoftware.luwrote: Le 11/09/2013 07:51, Richard Mace a écrit : Hi, Can anyone give me an example of adding and retrieving an integer value to a TTreenode via it's data property please? I've tried the below, but it doesn't seem to work. Set: with tvMain.Items.AddChildObject(tvMain.Selected,'string',TObject(fUserList.Items[I].Id)) do change to: with tvMain.Items.AddChildObject(tvMain.Selected,'string', *Pointer*(fUserList.Items[I].Id)) do and getting as, throws an exception on start: procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin ShowMessage('Node ' + IntToStr(Integer(Node.Data))); change to: ShowMessage('Node ' + IntToStr(*PtrInt***(Node.Data))); Antonio. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Le 11/09/2013 07:51, Richard Mace a écrit : Hi, Can anyone give me an example of adding and retrieving an integer value to a TTreenode via it's data property please? I've tried the below, but it doesn't seem to work. Set: with tvMain.Items.AddChildObject(tvMain.Selected,'string',TObject(fUserList.Items[I].Id)) do change to: with tvMain.Items.AddChildObject(tvMain.Selected,'string', *Pointer*(fUserList.Items[I].Id)) do and getting as, throws an exception on start: procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin ShowMessage('Node ' + IntToStr(Integer(Node.Data))); change to: ShowMessage('Node ' + IntToStr(*PtrInt***(Node.Data))); Antonio. end; Thanks in advance Richard -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On 11/09/2013 09:24, Antonio Fortuny wrote: Le 11/09/2013 07:51, Richard Mace a écrit : procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin ShowMessage('Node ' + IntToStr(Integer(Node.Data))); change to: ShowMessage('Node ' + IntToStr(*PtrInt***(Node.Data))); Also unless you want the treeview to behave as if it were fully initialised with Data integer values of zero, you would need to add: procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin if Assigned(Node) then ShowMessage('Node ' + IntToStr(PtrInt(Node.Data))); -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
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 Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Thanks for the reply. Can't it be type casted because both a pointer and integer are 4 bytes? On 11 Sep 2013 10:46, 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 Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On Wed, Sep 11, 2013 at 3:24 PM, Richard Mace richard.m...@gmail.com wrote: Can't it be type casted because both a pointer and integer are 4 bytes? They are both 4 bytes only in 32-bit computers. Juha -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On 2013-09-11 14:02, Juha Manninen wrote: They are both 4 bytes only in 32-bit computers. +1 Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Richard Mace schrieb: Thanks for the reply. Can't it be type casted because both a pointer and integer are 4 bytes? Dunno about Lazarus, but casts work in Delphi. Hint: pointers may be longer than integers, but never shorter. So you won't loose information when e.g. storing an 32 bit integer into a 64 bit pointer field. Consequently the opposite direction, i.e. storing an pointer in an integer field, may not work. That's why newer Delphi versions also have the Tag properties expanded, so that it's possible to store pointers there. DoDi -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Antonio Fortuny schrieb: Le 11/09/2013 07:51, Richard Mace a écrit : Hi, Can anyone give me an example of adding and retrieving an integer value to a TTreenode via it's data property please? I've tried the below, but it doesn't seem to work. Set: with tvMain.Items.AddChildObject(tvMain.Selected,'string',TObject(fUserList.Items[I].Id)) do change to: with tvMain.Items.AddChildObject(tvMain.Selected,'string', *Pointer*(fUserList.Items[I].Id)) do I'd store fUserList.Items[I] there, which is an address and allows access to further values later. DoDi -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On 11/09/13 14:02, Juha Manninen wrote: On Wed, Sep 11, 2013 at 3:24 PM, Richard Mace richard.m...@gmail.com wrote: Can't it be type casted because both a pointer and integer are 4 bytes? They are both 4 bytes only in 32-bit computers. Juha And if your program is compiled to 32bit executable and ran on 64bit mode Windows in compat mode (e.g. win7+)? (i guess this question is rhetorical ;) -L. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On 11/09/2013 18:03, Flávio Etrusco wrote: On Wed, Sep 11, 2013 at 5:41 AM, Howard Page-Clark h...@talktalk.net wrote: Also unless you want the treeview to behave as if it were fully initialised with Data integer values of zero, you would need to add: procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin if Assigned(Node) then ShowMessage('Node ' + IntToStr(PtrInt(Node.Data))); I guess you mean if Assigned(Node.Data) then ? Indeed that is what I meant, not what I wrote! -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On Wed, Sep 11, 2013 at 5:41 AM, Howard Page-Clark h...@talktalk.net wrote: Also unless you want the treeview to behave as if it were fully initialised with Data integer values of zero, you would need to add: procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin if Assigned(Node) then ShowMessage('Node ' + IntToStr(PtrInt(Node.Data))); I guess you mean if Assigned(Node.Data) then ? -Flávio -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
Howard Page-Clark schrieb: On 11/09/2013 18:03, Flávio Etrusco wrote: On Wed, Sep 11, 2013 at 5:41 AM, Howard Page-Clark h...@talktalk.net procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin if Assigned(Node) then ShowMessage('Node ' + IntToStr(PtrInt(Node.Data))); I guess you mean if Assigned(Node.Data) then ? Indeed that is what I meant, not what I wrote! In this case you can omit the if entirely. DoDi -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On Wed, Sep 11, 2013 at 6:19 AM, 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 Regards, Graeme I don't agree this is a rule of thumb. If you know what you're doing you should store whatever data fits in Data (pointer size) and avoid the hundreds of tiny annoying allocations... Regards, Flávio -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TTreenode.data
On 11 September 2013 10:19, Graeme Geldenhuys gra...@geldenhuys.co.ukwrote: 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
[Lazarus] TTreenode.data
Hi, Can anyone give me an example of adding and retrieving an integer value to a TTreenode via it's data property please? I've tried the below, but it doesn't seem to work. Set: with tvMain.Items.AddChildObject(tvMain.Selected,'string',TObject(fUserList.Items[I].Id)) do and getting as, throws an exception on start: procedure TfrmMain.tvMainChange(Sender: TObject; Node: TTreeNode); begin ShowMessage('Node ' + IntToStr(Integer(Node.Data))); end; Thanks in advance Richard -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus