English 中文(简体)
Delphi: Proper time to subclass, and restore, a control?
原标题:

What is the correct place/time to start subclassing a control?

What is the proper time to restore the original window proc?

Right now i subclass during form creation:

procedure TForm1.FormCreate(Sender: TObject);
begin
   FOldPanel1WindowProc := Panel1.WindowProc;
   Panel1.WindowProc := Panel1WindowProc;
end;

and i restore the subclassing during form destruction:

procedure TForm1.FormDestroy(Sender: TObject);
begin
   Panel1.WindowProc := FOldPanel1WindowProc;
end;

This works fine, as long as i don t use ThemeManager, which subclasses controls itself. As soon as a try to subclass a control that ThemeManager also sub-classes, i get very nasty errors.

i assume it s becuase i should not start the subclass during Create and restore it during Destroy. So what is the properly documented time to subclass and unsubclass a control in Delphi?

最佳回答

It s not clear from your question but I assume you get the errors when you re trying to restore the old window procedure in the form s OnDestroy event handler.

ThemeManager reverts its subclassing when processing WM_DESTROY for a control. Therefore you probably have to do the same: watch for WM_DESTROY in your new window procedure and revert your subclassing first, then call the old window procedure (and let ThemeManager do the same thing).

I haven t tested this but I think it should work.

问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签