Delphi XE2, vcl styles that recreate a window handle

After applying the new style at runtime, the MainForm of my application creates a new window handle - is there any way to stop this or reassign Handle, as I get tons of the following error:

'System error. Code: 1400. Invalid window handle

Is there a way to manipulate a process that forces a new descriptor to be assigned?

I decided to do this as follows:

My main form created an invisible helper form that never displays, but it has visual components - it threw a descriptor error when trying to redraw these visual components, so I replaced the corresponding components with objects (note that I did not write this code originally).

+5
source share
1 answer

Unable to avoid re-creating window handles. Instead, override the window methods CreateWndand DestroyWndso that you are notified of the window being restored.

Also, avoid maintaining permalinks to window handles that may be destroyed. Instead, read the property Handleevery time you need it. Then you do not have to follow the notifications.

Beware of reading Handlefrom another thread, although this may cause the window to become associated with the wrong thread. Wrap any code that should interact with the VCL window in a method that you call through Synchronizeor Queue.

+5
source

All Articles