0

I am using Delphi XE5. I want to add VCL styles to one of my projects but having a problem. After I set the new vcl style, all handles change. For example i am having problem with listview if there are already items and if i have active tcp sockets, they don't work anymore. I need to restart app and choose the style on startup or i need to re-create everything but this is annoying. I can not paste any code now as i am out of my development pc. But i believe you have also faced this problem?

Can anyone tell me the best and safest way to change vcl syles on runtime?

Thanks

blacksun
  • 733
  • 7
  • 24
  • That's another reason why you shouldn't tie your data with UI controls. If you'd have a collection and use a list view in virtual mode, you'd have no such problem. – TLama Jul 22 '14 at 11:20
  • But how about sockets? – blacksun Jul 22 '14 at 11:21
  • Information about socket has no relationship to a list view item. There are data that you store directly to the items, aren't they ? Having a collection like `TList` would heal this problem whatever the `TSocketInfo` contains (it may contain reference to the list view, or information about socket if your view shows a connection per item). – TLama Jul 22 '14 at 11:26
  • @TLama Windows async sockets receive windows messages. To do so they need a Window handle. Using a window handle that is subject to recreation is a common failure mode. – David Heffernan Jul 22 '14 at 11:34
  • @David, so you think that OP subclassed list view to receive messages from async sockets ? blacksun, what is the underlying design that you use ? – TLama Jul 22 '14 at 11:37
  • @TLama I'm assuming that this is the problem. I doubt the list view handle was used. More likely the form handle. From the Q, *all handles change*, *if i have active tcp sockets, they don't work anymore*. I could have mis-diagnosed the problem of course. – David Heffernan Jul 22 '14 at 11:39

1 Answers1

4

Changing VCL styles at runtime results in window recreation. There's nothing you can do about that. Furthermore, window recreation is one of the realities of the VCL. Your program can face it at other times, when some other event leads to VCL window recreation. So, your problem is not really directly related to VCL styles. Rather your problem is that you are using for socket communications window handles whose lifetimes are shorter than they need to be.

The solution is to use window handles whose lifetimes you control. Use AllocateHWnd to create such window handles.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490