We help IT Professionals succeed at work.

Using Item.Data in TCustomListView

baudewyns
baudewyns asked
on
I got a EAccessViolation error at run time during termination of the program after adding items with an object or record attached on it.
If I clear the list using an embedded PopUp menu before termination, it's OK.
If I clear the list, from outside the component, using also the method Clear, it's not OK.
What's wrong ?

I hope my explanation clear enough.
Bob
Comment
Watch Question

Commented:
Please show us how you fill the Data property and how you clear it. Some code, please...   :-)

Regards, Madshi.
Commented:
If you fill Data with newly created objects you should MANUALLY free them then clearing listview items. Something like:

procedure TForm1.ListView1Deletion(Sender: TObject; Item: TListItem);
begin
  TObject(Item.Data).Free;
end;

Author

Commented:
How to implement Deletion inside a new class derived from TCustomListView ?

Commented:
it's always agood approach to be more carefull with such code and use the function assigned to see if the item.data is assigned.

try this code

procedure TForm1.ListView1Deletion(Sender: TObject; Item: TListItem);
begin
 if Assigned(Item.Data) then
   TObject(Item.Data).Free;
end;


Explore More ContentExplore courses, solutions, and other research materials related to this topic.