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

Karl Reynolds kreynolds at chocfishsoft.co.nz
Tue Feb 16 16:16:21 NZDT 2010


On Tue, Feb 16, 2010 at 3:57 PM, Jolyon Smith <jsmith at 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:

Hmm... empirically I would have to say it does.

type
  TIPRListBox = class(TListBox);

procedure TForm1.Button1Click(Sender: TObject);

  function GetValue(AListBox: TListBox; AIndex: Integer): Integer;
  begin
    Result := TIPRListBox(AListBox).GetItemData(AIndex);
    if GetLastError <> 0 then RaiseLastOSError;
  end;

begin
  ListBox1.Items.AddObject('foo', TObject(0));
  ListBox1.Items.AddObject('foo', TObject(-1));
  ShowMessage(IntToStr(GetValue(ListBox1, 0)));
  ShowMessage(IntToStr(GetValue(ListBox1, 1)));
  ShowMessage(IntToStr(GetValue(ListBox1, 2)));
end;

Tested results: 0, -1, <invalid index error>

I'm using D2006, and you?

Cheers,
Karl


More information about the Delphi mailing list