statement of problem:
If you have not used Taction, you may not say that you will delphi. TACTION greatly simplifies the association of interface logic and accelerates the development of projects. However, when I use a lot of TACTION in the program, I don't intend to find such a problem: if there is more than 100 TACTION in a form of the program, when running this program, just quickly move the mouse on the form, CPU The occupancy will be around 30%.
Why have such a high CPU?
After using Spy debugging, it is found that once the mouse moves on the form, the program will send a WM_UPDATE message frequently. After further debugging, TCONTAINEDACTION.UPDATE () is frequently called by TActionManager. As helping the documentation: When the application is idle, all TXXXAction.onUpdate events are triggered. Since the idle state is frequent, OnUpdate is also triggered frequently, this is the true cause of improper CPU occupation.
solution
If you don't use TXXXAction.onUpdate in your program, you can block TActionManager to query and trigger txxxxaction.onupdate. The specific implementation code is as follows:
uses FastcodePatch {http://fastcode.sourceforge.net/}; procedure TContainedActionUpdateStub; asm call TContainedAction.Update; end; type TContainedActionPatch = class (TContainedAction) public function Update: Boolean; override; end; function TContainedActionPatch.Update: Boolean; begin Result: = False; end; function DisableTActionOnUpdate (ActnList: TActionList): Boolean; var I: Integer; begin Result: = True; for I: = 0to ActnList.ActionCount - 1do if Assigned (ActnList.Actions [I] .OnUpdate ) The begin result: = false; Break; End; if Result The begin fastcodeaddresspatch (@tcontainedactionupdatestub), @ tcontainedactionpatch.Update; end;
The best operating position of this code is on the oncreate () event of your program form. Of course, if you want to completely solve this problem, you can modify TContainedAction.Update in actnlist.pas, or submit an application to make Codeger to improve this issue.
to sum up
This article shows that excessive use of TXXXXAction components may result in excessive CPU occupancy issues. And provide patch code to solve this problem. Although there is no latest version of Delphi in my hand, it is estimated that this problem will not be corrected by Codegear.
Click here to view the English version of this article