Nope. What is expected is a 32-bit value. It is only the VCL that fabricates a "TObject" façade for that stored value, in an attempt to be helpful. If you only want to store an integer or other 32-bit value then casting to/from TObject() is perfectly valid since the value is merely passed to and fro across the VCL layer to the underlying 32-bit storage slot provided by Win32.
The fact that -1 doesn't work IS a bug because the error only occurs as result of naïve, and imho incorrect, error handling. If you removed all extraneous error handling from the VCL code and allowed/required the application to handle the Win API responses directly, then there is no problem with storing -1 in such values, as long as your code is written to expect it. > -----Original Message----- > From: delphi-boun...@delphi.org.nz [mailto:delphi- > boun...@delphi.org.nz] On Behalf Of Alister Christie > Sent: Tuesday, 16 February 2010 1:55 p.m. > To: NZ Borland Developers Group - Delphi List > Subject: Re: [DUG] Is it a bug in latest version of Delphi? > > I think the point I was trying to make is that it is that the method > (/array indexer or whatever) was expecting a TObject - passing anything > else could result in unexpected results. The fact that -1 doesn't work > is therefor not a bug (unless you can have 1 byte sized objects). > > Alister Christie > Computers for People > Ph: 04 471 1849 Fax: 04 471 1266 > http://www.salespartner.co.nz > PO Box 13085 > Johnsonville > Wellington > > > > Jolyon Smith wrote: > >> you should care greatly, because this is violating OOP principles > >> > > > > I care about code that works and gets a job of work done. "OO > Principles" are for the classroom. > > > > > > > >> Obviously the GetObject source cares somewhat about what -1 points > to. > >> > > > > No, it doesn't. It simply gets confused because the Windows API uses > "-1" to indicate that an error occurred in retrieving an item's data > and the VCL is then naively assuming that ANY error in retrieving an > item's data must be a List Index error. > > > > Even though it could (and should) specifically test for index > validity before calling the API and so discount that possible source of > an error from the outset. > > > > Indeed, the TObject(-1) result is cast BACK to a LongInt(-1) for > testing against the simple value LB_ERR (which == -1) ... the source of > this error has nothing what-so-ever to do with the casting of the value > as TObject. > > > > > > > > _______________________________________________ > > NZ Borland Developers Group - Delphi mailing list > > Post: delphi@delphi.org.nz > > Admin: http://delphi.org.nz/mailman/listinfo/delphi > > Unsubscribe: send an email to delphi-requ...@delphi.org.nz with > Subject: unsubscribe > > > > > _______________________________________________ > NZ Borland Developers Group - Delphi mailing list > Post: delphi@delphi.org.nz > Admin: http://delphi.org.nz/mailman/listinfo/delphi > Unsubscribe: send an email to delphi-requ...@delphi.org.nz with > Subject: unsubscribe _______________________________________________ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe