Board index » delphi » ListView bug????

ListView bug????

Hi,

I just discovered that the following codes will generates A/V:

procedure TMainForm.ListView1SelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
   lClickedDevice := ListView1.GetItemAt( Item.Position.x, Item.Position.y
);

   if (Item <> nil) then
   begin
      popupitem := lClickedDevice.data; <- this line causes A/V  becoz
lClickedDevice is nil
   end;
end;

This A/V i pointed at that line caused by selecting the items in the
ListView exceeded the available items that can be view on the current area
(meaning that I need to scroll down to see more items)).

Can anyone help?

--
UK Time:1337

------------------------------------------------------
To Know The Road Ahead, Ask Those Who Had Returned.

Michael

 

Re:ListView bug????


Hi Mike,

I think, TListItem.Position is only valid, if ViewStyle is vsIcon or
vsSmallIcon. What Style are you using in your ListView?

Hans-Jrgen

Re:ListView bug????


oh, i forgot to mention to you that i am using vsIcon

Quote
"Hans-Jrgen Schnorrenberg" wrote:

> Hi Mike,

> I think, TListItem.Position is only valid, if ViewStyle is vsIcon or
> vsSmallIcon. What Style are you using in your ListView?

> Hans-Jrgen

--
UK Time:

------------------------------------------------------
To Know The Road Ahead, Ask Those Who Had Returned.

Michael

Re:ListView bug????


I tried used GetNextItem(...) with sdBelow flag and it works magically...is
that the right mehtod?

Quote
Mike wrote:

> oh, i forgot to mention to you that i am using vsIcon

> "Hans-Jrgen Schnorrenberg" wrote:

> > Hi Mike,

> > I think, TListItem.Position is only valid, if ViewStyle is vsIcon or
> > vsSmallIcon. What Style are you using in your ListView?

> > Hans-Jrgen

> --
> UK Time:

> ------------------------------------------------------
> To Know The Road Ahead, Ask Those Who Had Returned.

> Michael

--
UK Time:

------------------------------------------------------
To Know The Road Ahead, Ask Those Who Had Returned.

Michael

Re:ListView bug????


Hi Mike,

I do not understand another thing in your code:

procedure TMainForm.ListView1SelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
   lClickedDevice := ListView1.GetItemAt( Item.Position.x, Item.Position.y
);

   if (Item <> nil) then
   begin
      popupitem := lClickedDevice.data; <- this line causes A/V  becoz
lClickedDevice is nil
   end;
end;

First you call Item.Position.X, but in the next line you test, if Item is
not nil; If Item is nil, Item.Position.X must cause an AV!
But if Item is assigned, your code should work, although catching
IClickedDevice in such a way makes no sense (you can simply replace
lClickedDevice := ListView1.GetItemAt( Item.Position.x, Item.Position.y);.
by lClickedDevice := Item;)

Hans-Jrgen

Other Threads