brookapplication.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (*
  2. Brook for Free Pascal
  3. Copyright (C) 2014-2019 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. { Application interface. }
  11. unit BrookApplication;
  12. {$i brook.inc}
  13. interface
  14. uses
  15. BrookConsts, BrookClasses, BrookException, BrookMessages, Classes;
  16. type
  17. { Handles exceptions for application. }
  18. EBrookApplication = class(EBrook);
  19. { Interface of the application. }
  20. IBrookApplication = interface(IBrookInterface)[BROOK_APP_GUID]
  21. { Creates an instance of the type specified by the @code(AInstanceClass)
  22. parameter and assigns it to the variable given by the @code(AReference)
  23. parameter. The owner of the new instance is the @code(Application) object. }
  24. procedure CreateForm(AInstanceClass: TComponentClass; out AReference);
  25. { Gets whether the application is terminated. }
  26. function GetTerminated: Boolean;
  27. { Returns the instance of broker application. }
  28. function Instance: TObject;
  29. { Initializes and runs the application. }
  30. procedure Run;
  31. { Terminates the application. }
  32. procedure Terminate;
  33. { Checks whether the application is terminated. }
  34. property Terminated: Boolean read GetTerminated;
  35. end;
  36. { Returns the application instance. }
  37. function BrookApp: IBrookApplication;
  38. { Returns the application instance maintaining compatibility with legacy code. }
  39. function Application: IBrookApplication;
  40. { Register the application. }
  41. procedure BrookRegisterApp(AApp: IBrookApplication);
  42. { Unregister the application. }
  43. procedure BrookUnregisterApp;
  44. implementation
  45. var
  46. _BrookAppService: IBrookApplication = nil;
  47. function BrookApp: IBrookApplication;
  48. begin
  49. if not Assigned(_BrookAppService) then
  50. raise EBrookApplication.Create('BrookApp',
  51. SBrookNoApplicationRegisteredError);
  52. Result := _BrookAppService;
  53. end;
  54. function Application: IBrookApplication;
  55. begin
  56. Result := BrookApp;
  57. end;
  58. procedure BrookRegisterApp(AApp: IBrookApplication);
  59. begin
  60. if Assigned(_BrookAppService) then
  61. raise EBrookApplication.Create('BrookRegisterApp',
  62. SBrookApplicationAlreadyRegisteredError);
  63. _BrookAppService := AApp;
  64. end;
  65. procedure BrookUnregisterApp;
  66. begin
  67. _BrookAppService := nil;
  68. end;
  69. end.