Win API returns -1 to indicate "an error". Any error. Not a specific error. Certainly not specifically a list index error.
Unfortunately, the Win API return value is ALSO the "Item data" value. So if you store -1 and get -1 back it could be an error or it could be the valid result. The VCL assumes that if it gets -1 back then it must be an error. It then makes matters worse by further assuming that it must be a list index error. What it should do is check the list index provided *itself* BEFORE sending that index to the WinAPI and then simply give the caller back whatever value the WinAPI yields (or at least raise LastOSError, not some assumed exception class). This is a case of the VCL trying to be too helpful and making a botched job of it in the process. And as I pointed out, it is now (as of Delphi 2006 at least) fixed (poorly, imho, but still effectively fixed) in comboboxstrings, just not listboxstrings. It is similar to the error handling in TWinControl.GetDeviceContext() that naively assumes that a GetDCEx() result of 0 (zero) must indicate an EOutOfResources condition. That bit of "intern code" cost me many lost hours trying to track down a resource leak when the true problem was actually an invalid window handle !!! From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On Behalf Of Kyley Harris Sent: Tuesday, 16 February 2010 2:51 p.m. To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Is it a bug in latest version of Delphi? interesting > if Longint(Result) = LB_ERR then Error(SListIndexError, Index); it would seem that the error is not in delphi at all. Well.. they are simply raising the Windows error which say that -1 is the error result for a bad index access from windows. if delphi were to ignore this error and you asked for the value at index[99] which was out of bounds and you got -1 instead of an error I think there would be the same number of complaints from the other side. Clearly its the windows API that considers -1 invalid.. not delphi. On Tue, Feb 16, 2010 at 2:24 PM, Karl Reynolds <kreyno...@chocfishsoft.co.nz> wrote: On Tue, Feb 16, 2010 at 1:55 PM, Alister Christie <alis...@salespartner.co.nz> wrote: > 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. Only if you stipulate that you have to remain ignorant of the function internals. The TObject is converted back and forth from a LongInt in order to store it anyway (see GetObject and PutObject). > The fact that -1 doesn't work > is therefor not a bug (unless you can have 1 byte sized objects). var x: longint; x := -1; // Four bytes (May the source be with you). Cheer, Karl _______________________________________________ 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 -- Kyley Harris Harris Software +64-21-671-821
_______________________________________________ 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