Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TListView - Clearing the list from within a TListViewItemClick event.


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 17, 2014 12:16 PM Last Post By: Martin Waller
Martin Waller

Posts: 12
Registered: 10/12/14
TListView - Clearing the list from within a TListViewItemClick event.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:18 AM
Hi,

I have a TListView object on screen and when the user clicks on an item I want to rebuild the contents of the TListView. At the moment I'm clearing the TListView items from within the click handler and expecting to be able to rebuild the list. It does not like that way of doing things and crashes in the MouseDown event. Looks like it still expects the original listview item to be around!

Is there a preferred way of doing this I wonder?

Many thanks

Martin
Eli M

Posts: 1,346
Registered: 11/9/13
Re: TListView - Clearing the list from within a TListViewItemClick event.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 11:17 AM   in response to: Martin Waller in response to: Martin Waller
I had this same issue. I didn't figure out a solution so if you do please post it.

Here is a list of the events that happen when you touch a TListViewItem:
http://www.fmxexpress.com/listview-onitemclick-and-swipe-to-delete-event-order-in-delphi-xe6-firemonkey-on-android/

I mention the event list because you can see how lots of events fire after OnMousedown which operate on the TListViewItem after it has been deleted (which is the cause of the error). Maybe we can delete in OnItemClickEx?
Martin Waller

Posts: 12
Registered: 10/12/14
Re: TListView - Clearing the list from within a TListViewItemClick event.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 12:16 PM   in response to: Eli M in response to: Eli M
Eli M wrote:
I had this same issue. I didn't figure out a solution so if you do please post it.

Here is a list of the events that happen when you touch a TListViewItem:
http://www.fmxexpress.com/listview-onitemclick-and-swipe-to-delete-event-order-in-delphi-xe6-firemonkey-on-android/

I mention the event list because you can see how lots of events fire after OnMousedown which operate on the TListViewItem after it has been deleted (which is the cause of the error). Maybe we can delete in OnItemClickEx?

Hi,

In the end I used the ViewChange event and did the processing there. I located the clocked entry from the .Selected property. On reflection though I'll try the suggestion in the next reply the TThread... idea.

On the whole venturing into the Delphi world from the C# .Net world is hard going!

Martin

procedure TMainForm.MainListViewChange(Sender: TObject);

var
ListViewItem : TListViewItem;
Blob : TBlob;
BlobPrefix : TBlobPrefix;
//FileDetailForm : TFileDetailForm;
VariableTagObject : TVariableTagObject;

begin
ListViewItem := Self.MainListView.Selected;
Kees Vermeulen

Posts: 23
Registered: 11/7/99
Re: TListView - Clearing the list from within a TListViewItemClick event.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 11:55 AM   in response to: Martin Waller in response to: Martin Waller
On 17/10/14 15:18, Martin Waller wrote:
Hi,

I have a TListView object on screen and when the user clicks on an item I want to rebuild the contents of the TListView. At the moment I'm clearing the TListView items from within the click handler and expecting to be able to rebuild the list. It does not like that way of doing things and crashes in the MouseDown event. Looks like it still expects the original listview item to be around!

Is there a preferred way of doing this I wonder?

Martin,

Use something like:

TThread.Queue(
procedure
begin
RebuildListview;
end);

This will execute the code in RebuildListview from the main thread once
all others events have been handled. TThread.Queue will not wait but
posts the call to RebuildListview into the main message queue.

Kees
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02