Pointers and TObject are unsigned integers (cardinals) not (integer) casting to -1 is converting to the cardinal equvalent, which when pulled back is making an out of bounds integer..<div><br></div><div>just a guess and it probably has something to do with the compiler typecasting rules you have designated.<br>
<br><div class="gmail_quote">On Tue, Feb 16, 2010 at 11:41 AM, Ross Levis <span dir="ltr">&lt;<a href="mailto:ross@stationplaylist.com">ross@stationplaylist.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I often use the Object property of listbox and TStringList items to store pointers, or just numbers for array subscripts.  I don&#39;t see any problem doing that as it can save a lot of time.  It is just an integer variable internally.  I seem to remember coming across the same problem once (D7) and had to use -2 instead of -1 to indicate no value or something of that nature.  I&#39;m not sure why.  The integer always exists and defaults to a value of 0.<br>

<br>
Ross.<br>
<div class="im"><br>
-----Original Message-----<br>
From: <a href="mailto:delphi-bounces@delphi.org.nz">delphi-bounces@delphi.org.nz</a> [mailto:<a href="mailto:delphi-bounces@delphi.org.nz">delphi-bounces@delphi.org.nz</a>] On Behalf Of Alister Christie<br>
Sent: Tuesday, 16 February 2010 10:20 a.m.<br>
To: NZ Borland Developers Group - Delphi List<br>
Subject: Re: [DUG] Is it a bug in latest version of Delphi?<br>
<br>
I can confirm that<br>
  ListBox1.Items.AddObject(&#39;foo&#39;, TObject(-1));<br>
</div>  ShowMessage(IntToStr(Integer(ListBox1.Items.Objects[0])));<br>
gives an error but<br>
  ListBox1.Items.AddObject(&#39;foo&#39;, TObject(0));<br>
  ShowMessage(IntToStr(Integer(ListBox1.Items.Objects[0])));<br>
does not<br>
<br>
I think casting -1 to an object is probably not the best idea - what<br>
memory location does this point to anyway? 0xFFFFFFFF?<br>
<br>
Alister Christie<br>
Computers for People<br>
Ph: 04 471 1849 Fax: 04 471 1266<br>
<a href="http://www.salespartner.co.nz" target="_blank">http://www.salespartner.co.nz</a><br>
PO Box 13085<br>
Johnsonville<br>
Wellington<br>
<br>
<br>
<br>
sinu sudhakaran wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I came across a strange bug(???) in latest versions of Delphi.<br>
&gt;<br>
&gt; Have a look at the following code.<br>
<div class="im">&gt;<br>
&gt; procedure TForm1.Button1Click(Sender: TObject);<br>
&gt; var<br>
</div>&gt; i : integer;<br>
&gt; begin<br>
&gt; ComboBox1.Clear;<br>
&gt; ComboBox1.Items.AddObject(&#39;All Locations&#39;, TObject(-1));<br>
&gt; ComboBox1.Items.AddObject(&#39;Only this Location&#39;, TObject(0));<br>
&gt; ComboBox1.Items.AddObject(Test Location&#39;, TObject(1));<br>
&gt;<br>
&gt; i := Integer(ComboBox1.Items.Objects[0]);<br>
&gt; showmessage(inttostr(i));<br>
&gt; end;<br>
&gt;<br>
&gt; When I tried to run this code in Delphi 6 and Delphi 2007 , I am<br>
&gt; getting List Index out of bounds[0] error in Showmessage. When I tried<br>
&gt; -2, -3, -4… instead of -1 object , I got the proper output without any<br>
&gt; List index out of bounds error. Also I am getting -1 without any error<br>
&gt; when I tried this code in Delphi 3.<br>
&gt;<br>
&gt; Is it a bug in latest version of Delphi ? Any help is appreciated.<br>
&gt;<br>
&gt; Thank you<br>
&gt;<br>
&gt; Regards,<br>
&gt; Sinu<br>
&gt;<br>
&gt; &lt;<a href="http://sigads.rediff.com/RealMedia/ads/click_nx.ads/www.rediffmail.com/signatureline.htm@Middle" target="_blank">http://sigads.rediff.com/RealMedia/ads/click_nx.ads/www.rediffmail.com/signatureline.htm@Middle</a>?&gt;<br>

&gt;<br>
&gt;<br>
&gt; ------------------------------------------------------------------------<br>
<div><div></div><div class="h5">&gt;<br>
&gt; _______________________________________________<br>
&gt; NZ Borland Developers Group - Delphi mailing list<br>
&gt; Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
&gt; Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
&gt; Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br>
<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe</div></div></blockquote></div><br><br clear="all"><br>-- <br>Kyley Harris<br>Harris Software<br>
+64-21-671-821<br>
</div>