TApplication.DispatchAction change proposal
Original Reporter info from Mantis: lagprogramming
-
Reporter name:
Original Reporter info from Mantis: lagprogramming
- Reporter name:
Description:
TApplication.DispatchAction is found within lcl/include/application.inc
I propose an improved function result assignment.
Within existing code, initial "Result := False;" is a useless assignment when the function returns true.
I also consider it's better to set the result using a direct assignment instead of a "if...then...else if...then" statement in terms of both speed and size.
ORIGINAL CODE IS:
function TApplication.DispatchAction(Msg: Longint; Action: TBasicAction): Boolean;
var
Form: TCustomForm;
begin
Result := False;
Form := Screen.ActiveForm;
if (Form <> nil) and (Form.Perform(Msg, 0, PtrInt(Action)) = 1) then
Result := True
else
if (MainForm <> Form) and (MainForm <> nil) and (MainForm.Perform(Msg, 0, PtrInt(Action)) = 1) then
Result := True;
// Disable action if no "user" handler is available
if (not Result) and (Action is TCustomAction) and
TCustomAction(Action).Enabled and TCustomAction(Action).DisableIfNoHandler then
TCustomAction(Action).Enabled := Assigned(Action.OnExecute);
end;
PROPOSED CODE IS:
function TApplication.DispatchAction(Msg: Longint; Action: TBasicAction): Boolean;
var Form:TCustomForm;
begin
Form:=Screen.ActiveForm;
Result:=((Form<>nil)and(Form.Perform(Msg,0,PtrInt(Action))=1))or
((MainForm<>Form)and(MainForm<>nil)and(MainForm.Perform(Msg,0,PtrInt(Action))=1));
// Disable action if no "user" handler is available
if (not Result) and (Action is TCustomAction) and
TCustomAction(Action).Enabled and TCustomAction(Action).DisableIfNoHandler then
TCustomAction(Action).Enabled := Assigned(Action.OnExecute);
end;
P.S. I didn't created a patch because I use a different code formatting.
Mantis conversion info:
- Mantis ID: 26885
- Build: SVN 46592
- Version: 1.2.7 (SVN)
- Fixed in revision: r46602 (#00fc7489)