Delphi: How to remove subclasses in reverse order?

跟風遠走 提交于 2019-12-04 09:58:49
Rob Kennedy

Change your code to call SetWindowSubclass, as the article you linked to advises. But that only works if everyone uses the same API, so patch Theme Manager to use the same technique. The API was introduced in Windows XP, so there's no danger that it's not available on the systems where it would be needed.

There should be no problem with patching Theme Manager. It's designed to support Windows XP, which Microsoft doesn't support anymore, and to support Delphi 4 through 6, which Borland doesn't support anymore. Since development has ceased on all relevant products, it is safe for you to fork the Theme Manager project without risk of falling behind due to future updates.

You're not really introducing a dependency. Rather, you're fixing a bug that's only present when both window-appearance libraries are in use at the same time. Users of your library don't need to have Theme Manager for yours to work, but if they wish to use both, they need to use Theme Manager with your patches applied. There should be little objection to that since they already have the base version, so it's not like they'd be installing an entirely new library. They'd just be applying a patch and recompiling.

Rather than subclassing the TApplication window, perhaps you can use AllocateHWnd() instead to receive the same broadcasts separately, since it is a top-level window of its own.

I think I would do the following:

  • Put a reference to ThemeServices in the initialization section of ThemeSrv.pas.
  • Put a reference to DwmServices in the initialization section of DwmSrv.pas (I'm guess the name of your unit).

Since units are finalised in reverse order from the order of initialisation, your problem will be solved.

Why don't you just use the ApplicationEvents and be done with it. No need to messing around with subclassing. The other way is to create only one subclass and create multi-notify events and subscribe as many as you wish.

Cheers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!