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"><<a href="mailto:ross@stationplaylist.com">ross@stationplaylist.com</a>></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'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'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('foo', TObject(-1));<br>
</div> ShowMessage(IntToStr(Integer(ListBox1.Items.Objects[0])));<br>
gives an error but<br>
ListBox1.Items.AddObject('foo', 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>
> Hi all,<br>
><br>
> I came across a strange bug(???) in latest versions of Delphi.<br>
><br>
> Have a look at the following code.<br>
<div class="im">><br>
> procedure TForm1.Button1Click(Sender: TObject);<br>
> var<br>
</div>> i : integer;<br>
> begin<br>
> ComboBox1.Clear;<br>
> ComboBox1.Items.AddObject('All Locations', TObject(-1));<br>
> ComboBox1.Items.AddObject('Only this Location', TObject(0));<br>
> ComboBox1.Items.AddObject(Test Location', TObject(1));<br>
><br>
> i := Integer(ComboBox1.Items.Objects[0]);<br>
> showmessage(inttostr(i));<br>
> end;<br>
><br>
> When I tried to run this code in Delphi 6 and Delphi 2007 , I am<br>
> getting List Index out of bounds[0] error in Showmessage. When I tried<br>
> -2, -3, -4… instead of -1 object , I got the proper output without any<br>
> List index out of bounds error. Also I am getting -1 without any error<br>
> when I tried this code in Delphi 3.<br>
><br>
> Is it a bug in latest version of Delphi ? Any help is appreciated.<br>
><br>
> Thank you<br>
><br>
> Regards,<br>
> Sinu<br>
><br>
> <<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>?><br>
><br>
><br>
> ------------------------------------------------------------------------<br>
<div><div></div><div class="h5">><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>
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>