TListView.OnDeletion() event does not triggers for Items on application closing
Original Reporter info from Mantis: squid
-
Reporter name: Squid
Original Reporter info from Mantis: squid
- Reporter name: Squid
Description:
If 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 reproduce:
1. 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 information:
Since 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.
Mantis conversion info:
- Mantis ID: 25431
- OS: Windows 7, 64-bit, SP1
- Platform: x86 ADM64
- Version: 1.0.14
- Fixed in revision: 44404 (#5047d8a8)