i tested getlasterror also and it does not fail when an invalid index is returned.
As i mentioned earlier.. index[99] will not fail.. you just get -1 :D pre-testing the range is the only bypass. or.. just store your data in a structure thats kinder to -1 :) On Tue, Feb 16, 2010 at 3:57 PM, Jolyon Smith <jsm...@deltics.co.nz> wrote: > Good luck with GetLastError(). There's nothing to indicate that > LB_GETITEMDATA processing will set a Windows "LastError". > > And empirically I would have to say that it doesn't: > > // On an empty Listbox1 .. > > r := SendMessage(Listbox1.Handle, LB_GETITEMDATA, 100, 0); > if GetLastError <> 0 then > RaiseLastOSError; > > if r = -1 then > ShowMessage('oops'); > > > Will yield only the "oops" message, no OS error. > > I am speculating (in this case I don't have the source for SendMessage() or > the LISTBOX wndproc) that SendMessage() isn't setting an error condition > (after all it is successfully sending a message and returning the result) > and that the LISTBOX wndproc doesn't SetLastError() when processing > LB_GETITEMDATA, at least not for an invalid item index. > > > > > -----Original Message----- > > From: delphi-boun...@delphi.org.nz [mailto:delphi- > > boun...@delphi.org.nz] On Behalf Of Karl Reynolds > > Sent: Tuesday, 16 February 2010 3:29 p.m. > > To: NZ Borland Developers Group - Delphi List > > Subject: Re: [DUG] Is it a bug in latest version of Delphi? > > > > On Tue, Feb 16, 2010 at 3:06 PM, Jolyon Smith <jsm...@deltics.co.nz> > > wrote: > > > Win API returns -1 to indicate “an error”. Any error. Not a > > specific > > > error. Certainly not specifically a list index error. > > > > Pardon me for being pedantic, but while I agree with everything else > > you said, I feel the need to reiterate that -1 isn't actually returned > > to *indicate* an error (and you mentioned the conflict between an > > error result and a valid result yourself at one point). It's just the > > value returned when an error has occured. And yes, that means the VCL > > code is wrong. > > > > GetLastError... I won't say it again, promise. ;) > > > > Cheers, > > 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 > > > _______________________________________________ > 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