brookapplication.pas 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. (*
  2. Brook framework, Application Interface
  3. Copyright (C) 2014 Silvio Clecio
  4. See the file LICENSE.txt, included in this distribution,
  5. for details about the copyright.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *)
  10. unit BrookApplication;
  11. {$i brook.inc}
  12. interface
  13. uses
  14. BrookConsts, BrookClasses, BrookException, BrookMessages, Classes;
  15. type
  16. { Handles exceptions for application. }
  17. EBrookApplication = class(EBrook);
  18. { Interface of the application. }
  19. IBrookApplication = interface(IBrookInterface)[BROOK_APP_GUID]
  20. { Creates an instance of the type specified by the @code(AInstanceClass)
  21. parameter and assigns it to the variable given by the @code(AReference)
  22. parameter. The owner of the new instance is the @code(Application) object. }
  23. procedure CreateForm(AInstanceClass: TComponentClass; out AReference);
  24. { Gets whether the application is terminated. }
  25. function GetTerminated: Boolean;
  26. { Returns the instance of broker application. }
  27. function Instance: TObject;
  28. { Initializes and runs the application. }
  29. procedure Run;
  30. { Terminates the application. }
  31. procedure Terminate;
  32. { Checks whether the application is terminated. }
  33. property Terminated: Boolean read GetTerminated;
  34. end;
  35. { Returns the application instance. }
  36. function BrookApp: IBrookApplication;
  37. { Returns the application instance maintaining compatibility with legacy code. }
  38. function Application: IBrookApplication;
  39. { Register the application. }
  40. procedure BrookRegisterApp(AApp: IBrookApplication);
  41. { Unregister the application. }
  42. procedure BrookUnregisterApp;
  43. implementation
  44. var
  45. _BrookAppService: IBrookApplication = nil;
  46. function BrookApp: IBrookApplication;
  47. begin
  48. if not Assigned(_BrookAppService) then
  49. raise EBrookApplication.Create('BrookApp',
  50. SBrookNoApplicationRegisteredError);
  51. Result := _BrookAppService;
  52. end;
  53. function Application: IBrookApplication;
  54. begin
  55. Result := BrookApp;
  56. end;
  57. procedure BrookRegisterApp(AApp: IBrookApplication);
  58. begin
  59. if Assigned(_BrookAppService) then
  60. raise EBrookApplication.Create('BrookRegisterApp',
  61. SBrookApplicationAlreadyRegisteredError);
  62. _BrookAppService := AApp;
  63. end;
  64. procedure BrookUnregisterApp;
  65. begin
  66. _BrookAppService := nil;
  67. end;
  68. end.