[DUG] Is it a bug in latest version of Delphi?

Jolyon Smith jsmith at deltics.co.nz
Tue Feb 16 15:57:00 NZDT 2010


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-bounces at delphi.org.nz [mailto:delphi-
> bounces at 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 <jsmith at 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 at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with
> Subject: unsubscribe




More information about the Delphi mailing list