ertank 28 Posted November 19, 2019 (edited) 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 Any help is appreciated. Thanks & regards, Ertan DragDrop.7z Edited November 19, 2019 by ertank Changed title Share this post Link to post
David Heffernan 2353 Posted November 19, 2019 (edited) 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 November 19, 2019 by David Heffernan Share this post Link to post
ertank 28 Posted November 19, 2019 I do debug run and execution does not stop at first line of DestroyWnd procedure at all. Share this post Link to post
David Heffernan 2353 Posted November 19, 2019 (edited) 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 November 19, 2019 by David Heffernan 1 Share this post Link to post
Stefan Glienke 2019 Posted November 19, 2019 The point is that DestroyWnd is never called on the TForm (tested with 10.3) thus FDropTarget never destroyed. Share this post Link to post
David Heffernan 2353 Posted November 19, 2019 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
David Heffernan 2353 Posted November 19, 2019 (edited) 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 November 19, 2019 by David Heffernan Share this post Link to post
ertank 28 Posted November 19, 2019 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