Board index » delphi » Onedited event in Ttreeview ?

Onedited event in Ttreeview ?

Hi,

I want to delete node when node.text is 'end'.

So I wrote :

procedure Tform1.Treeview1Edited(Sender: TObject; Node: TTreeNode;
  var S: String);
begin
    if S = 'end' then node.delete;
end;

And, I executed.
Access violation Error raised,  What's wrong above Code ?

 

Re:Onedited event in Ttreeview ?


There is nothing wrong with youre code. VCL is the problem here. After you
delete the node, VCL assigns the var string 'S' to the node...result is an
exception.

Try youre code in a other event.
As a test, i used GetSelectedIndex of the treeview and it works fine.

Quote
Kim Hyun-Chan wrote in message <6rtqin$g...@forums.borland.com>...
>Hi,

>I want to delete node when node.text is 'end'.

>So I wrote :

>procedure Tform1.Treeview1Edited(Sender: TObject; Node: TTreeNode;
>  var S: String);
>begin
>    if S = 'end' then node.delete;
>end;

>And, I executed.
>Access violation Error raised,  What's wrong above Code ?

Re:Onedited event in Ttreeview ?


Nothings wrong except you're killing an object in the middle of an event
that's included in the parameter list.  Lots of ways to deal with this
but if you get really stuck, simply store the Node to a local var in the
form (during the event your deleting it in now) and then generate a
custom message (PostMessage will do) and then write your own message
declaration in the form to delete that node.  It's really quite simple.

I had a similar trublem of a node being selected which launched a new
'pane' but the old pane contained the object being destroyed in the
OnDblClick event (which will produce a similar error).  I created the
message (as described above) and all turned out well.

Quote
Kim Hyun-Chan wrote:
> Hi,

> I want to delete node when node.text is 'end'.

> So I wrote :

> procedure Tform1.Treeview1Edited(Sender: TObject; Node: TTreeNode;
>   var S: String);
> begin
>     if S = 'end' then node.delete;
> end;

> And, I executed.
> Access violation Error raised,  What's wrong above Code ?

Other Threads