Jump to content
Sign in to follow this  
ertank

Overrided TForm.DestroyWnd is not executed

Recommended Posts

Hello,

 

I have found that stackoverflow code of @David Heffernan

https://stackoverflow.com/questions/4354071/how-can-i-allow-a-form-to-accept-file-dropping-without-handling-windows-messages

 

Attached is a project where I put it all together for my use case. However, it seems to leak some memory. I do not know why but TForm2.DestroyWnd seems not executed at all.

 

I simply run and close the application without doing anything. Below dialog is my leak report message

image.png.ce63add6fed053ac3e1ebe603fe1fe80.png

 

Any help is appreciated.

 

Thanks & regards,

Ertan

DragDrop.7z

Edited by ertank
Changed title

Share this post


Link to post

The code in the linked SO answer doesn't leak. 

 

Update: Er, it does leak. I updated it to override CreateWindowHandle and DestroyWindowHandle, as per discussion below. 

 

Sorry!! 

Edited by David Heffernan

Share this post


Link to post

I do debug run and execution does not stop at first line of DestroyWnd procedure at all.

Share this post


Link to post

You can presumably remove the drop target code and just create and free a TObject instead to show that the issue is not in the drop target code. 

 

Making a minimal example is really useful. 

Edited by David Heffernan
  • Like 1

Share this post


Link to post
2 minutes ago, Stefan Glienke said:

The point is that DestroyWnd is never called on the TForm (tested with 10.3) thus FDropTarget never destroyed.

Indeed. So one wonders why. 

Share this post


Link to post

I haven't got time to look at this in VCL code, but my guess from memory is that you need to be overriding CreateWindowHandle and DestroyWindowHandle instead of CreateWnd and DestroyWnd. 

 

CreateWindowHandle and DestroyWindowHandle are the methods tasked with he actual creation and destruction of the window. 

 

Probably when the form is torn down it just calls DestroyWindowHandle and not DestroyWnd. 

Edited by David Heffernan

Share this post


Link to post
4 minutes ago, David Heffernan said:

I haven't got time to look at this but my guess is that you need to be overriding CreateWindowHandle and DestroyWindowHandle instead of CreateWnd and DestroyWnd. 

 

CreateWindowHandle and DestroyWindowHandle are the methods tasked with he actual creation and destruction of the window. 

That did solve my problem.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×