<div dir="ltr"><div><div><div><div>Ok, that's reasonable, however:<br><br></div>1) If I use Move() is there a "manual" way to increate the string ref count?<br><br></div>2) why the error is gone if I change this line:<br>

<br>    prev := tv.Items.InsertObjectBehind(prev, p^.title, p);<br><br>to this:<br><br>    prev := tv.Items.InsertObjectBehind(prev, 'Node #' + IntToStr(i), p);<br>    <br></div>3) Why this error does not happen on node #0 and #3, but only node #1 and #2?<br>

<br></div>4) Why it behaves different on Windows and Linux?<br><br>Thanks! <br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/8/24 Martin <span dir="ltr"><<a href="mailto:lazarus@mfriebe.de" target="_blank">lazarus@mfriebe.de</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 23/08/2013 16:13, Xiangrong Fang wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
<br>
I encountered a strange SIGSEGV with the attached program.  To reproduce the problem:<br>
<br>
1) compile and run it.<br>
2) select "Node #2"<br>
3) click "Test" button, it will insert a node before the selected Node<br>
4) close the program<br>
<br>
There will be a SIGSEGV at the end of OnDestroy method.<br>
<br>
This problem is reproducible under Linux amd64 and Wine and Win7 (32bit). A strange thing is that on Linux or Wine, this error only occur on Node #1 and Node #2, but on Windows, it only occur on Node #2 and Node #3.<br>
<br>
Also, if you swap either of the 2 commented statements, this error is gone.<br>
<br>
I suspect this is caused by the AnsiString manager.  Could anyone explain why, or is this a bug?<br>
</blockquote>
<br></div></div>
Only had a quick look, please veryfy....<br>
<br>
 Move(tv.Selected.Data^, p^, SizeOf(TNode));<br>
  tv.Items.InsertObject(tv.<u></u>Selected, 'New Node', p);<br>
<br>
<br>
Move makes a copy of the node, including a copy of the ansistring (that is the pointer-part) in the node.<br>
so now you have 2 strings, referring the same string data, but you never increased the ref count.<br>
<br>
<br>
<br>
<br>
--<br>
______________________________<u></u>_________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org" target="_blank">Lazarus@lists.lazarus.<u></u>freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.<u></u>freepascal.org/mailman/<u></u>listinfo/lazarus</a><br>
</blockquote></div><br></div>