View Issue Details

IDProjectCategoryView StatusLast Update
0025431LazarusLCLpublic2014-03-11 10:20
ReporterSquid Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
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:
...
type
  TMyRec = record
    I: Integer;
  end;
  PMyRec = ^TMyRec;
...
implementation
...
procedure TForm1.Button1Click(Sender: TObject);
var
  MR: PMyRec;
  LI: TListItem;
begin
  LI := ListView1.Items.Add;
  LI.Caption := TimeToStr(Now);
  New(MR);
  LI.Data := MR;
end;
procedure TForm1.ListView1Deletion(Sender: TObject; Item: TListItem);
begin
  Dispose(PMyRec(Item.Data)); //Set breakpoint here
end;
4. Set breakpoint (see above)
5. Run the program
6. Press Button1 at least one time.
7. Close program

Result:
- 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
LazTarget-
Widgetset
Attached Files

Activities

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

TListItem.Destroy->TListItems.ItemDestroying->TCustomListView.ItemDeleted

procedure TCustomListView.ItemDeleted(const AItem: TListItem);
begin
  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
  DoDeletion(AItem);
end;

(Introduced in r6848 (http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=6848) 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