View Issue Details

IDProjectCategoryView StatusLast Update
0025431LazarusLCLpublic2014-03-11 10:20
ReporterSquid Assigned ToZeljan Rikalo  
Status resolvedResolutionfixed 
Platformx86 ADM64OSWindows 7, 64-bit, SP1 
Product Version1.0.14 
Summary0025431: TListView.OnDeletion() event does not triggers for Items on application closing
DescriptionIf there are the Items in TListView and application is closing the OnDeletion event is not triggers. It should be.
Deletion of Items during program execution works properly - OnDeletion triggers for each Item.
Calling ListView1.Items.Clear causes execution of OnDeletion everywhere in code except in FormDestroy event code!

For example:
If you use dynamic data and keep pointer on it in Item.Data then there will be no OnDeletion event, wich calls "Dispose(...)" or any useful code.
Delphi works correctly.
Steps To Reproduce1. Enable "Heaptrc Unit" in Project Options -> Linking
2. Place on the form ListView1:TListView and Button1:TButton.
3. Insert code:
  TMyRec = record
    I: Integer;
  PMyRec = ^TMyRec;
procedure TForm1.Button1Click(Sender: TObject);
  MR: PMyRec;
  LI: TListItem;
  LI := ListView1.Items.Add;
  LI.Caption := TimeToStr(Now);
  LI.Data := MR;
procedure TForm1.ListView1Deletion(Sender: TObject; Item: TListItem);
  Dispose(PMyRec(Item.Data)); //Set breakpoint here
4. Set breakpoint (see above)
5. Run the program
6. Press Button1 at least one time.
7. Close program

- No program stop at breakpoint
- Heaptrc Unit reports about unfreed memory
Additional InformationSince the program will be closed mem-leak does not metter, but it`s still WRONG.
The more that OnDeletion event can contains not only mem-freeing code. It must be executed.
TagsNo tags attached.
Fixed in Revision44404
Attached Files


Zeljan Rikalo

2014-01-12 11:34

developer   ~0072381

Please attach complete example project.

Bart Broersma

2014-01-12 12:35

developer   ~0072383

Last edited: 2014-01-12 18:17

View 5 revisions


procedure TCustomListView.ItemDeleted(const AItem: TListItem);
  DebugLn('TCustomListView.ItemDeleted ',dbgs(AItem),' FSelected=',dbgs(FSelected));
  if FSelected = AItem then InvalidateSelected;
  if FFocused = AItem then FFocused := nil;
  if csDestroying in Componentstate then Exit;
  ^^^^^^ this prevents the triggering of OnDeletion in the described scenario

(Introduced in r6848 ( by marc)

Zeljan Rikalo

2014-03-11 08:59

developer   ~0073619

Please test and close if ok.It will be merged to 1.2.2 too (if ok).

Issue History

Date Modified Username Field Change
2013-12-17 07:53 Squid New Issue
2014-01-12 11:34 Zeljan Rikalo LazTarget => -
2014-01-12 11:34 Zeljan Rikalo Note Added: 0072381
2014-01-12 11:34 Zeljan Rikalo Assigned To => Zeljan Rikalo
2014-01-12 11:34 Zeljan Rikalo Status new => feedback
2014-01-12 12:35 Bart Broersma Note Added: 0072383
2014-01-12 12:35 Bart Broersma Note Edited: 0072383 View Revisions
2014-01-12 12:42 Bart Broersma Note Edited: 0072383 View Revisions
2014-01-12 13:06 Bart Broersma Note Edited: 0072383 View Revisions
2014-01-12 18:17 Bart Broersma Note Edited: 0072383 View Revisions
2014-03-11 08:59 Zeljan Rikalo Fixed in Revision => 44404
2014-03-11 08:59 Zeljan Rikalo Note Added: 0073619
2014-03-11 08:59 Zeljan Rikalo Status feedback => resolved
2014-03-11 08:59 Zeljan Rikalo Resolution open => fixed