In Delphi I have an own class which is based on TList. It is TPetList. Every instance of TPetList can have some items of the class TPet. The instance of TPetList is displayed in a TListView component using a for loop.
TPet is based on TObject and has the following fields:
- city
- age
- breed
Now I have a list of checkboxes where the user can tick the breeds he wants to see. So if he only wants to see pets of breed XYZ I want to show only entries which have the value of “breed” set to “XYZ” while the order in TPetList and TListView must remain the same.
How can I do this?
If I delete the items in TPetList and show the rest in TListView, everything’s fine until the user wants to see another breed. This breed has been deleted before and can’t be showed.
Instead of deleting, try selecting out a new list. Something like this:
How you implement the criteria is up to you, but that’s the general idea. Remember that the list this returns is a sub-view and does not own the items it contains, so don’t free them when you free the filtered list.