Scenario:
- a TActionManager, a TAction, and a TButton (associated with this action)
- ActionManager constantly enables the Action in its OnUpdate event handler
- the code in the action event handler launches an external program using a ShellExecAndWait method (using Jedi Code Library JCL)
- requirement: the application should not allow to launch the application twice by clicking the button quickly another time
Problem:
- ShellExecAndWait does not block the application message loop, so the user can click while the external application is still open
- if he Action handler method disable the Action before the ShellExecAndWait call, the Update method will immediately re-enable it
So I could write like this
procedure TMyForm.OnMyAction(Sender: TObject);
begin
try
// notify Action Manager that the Action is temporarily disabled
SomeGlobalFlag := True;
// disable the action
(Sender as TAction).Enabled := False;
// do the call
ShellExecAndWait( ... );
finally
// enable the action
(Sender as TAction).Enabled := True;
// allow ActionManager to control the action again
SomeGlobalFlag := False;
end;
end;
Is there an easier way? As the title of this question says - could I block input for the execution of the external application?
This solution depends on the actual Action or ActionManager component. Still too much "boilerplate" code. Also very fragile, as it assumes that the Sender is a TAction instance.