uBasePluginFormNoPackge.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. unit uBasePluginFormNoPackge;
  2. interface
  3. uses
  4. Forms, uIPluginForm, Classes, superobject, uIMainForm, ComObj,
  5. SysUtils,
  6. mybean.core.intf, mybean.tools.beanFactory,
  7. mBeanMainFormTools,
  8. uICaption,uIMainApplication;
  9. type
  10. TBasePluginForm = class(TForm,
  11. IPluginForm,
  12. IFreeObject,
  13. ICaptionManager,
  14. IBeanConfigSetter)
  15. private
  16. FInstanceID: string;
  17. protected
  18. __pass:AnsiString;
  19. FBeanConfigStr:string;
  20. procedure DoClose(var Action: TCloseAction); override;
  21. protected
  22. function getCaption: PAnsiChar; stdcall;
  23. procedure setCaption(pvCaption: PAnsiChar); stdcall;
  24. protected
  25. /// <summary>
  26. /// 设置配置中的Config
  27. /// </summary>
  28. /// <param name="pvBeanConfig">
  29. /// 配置文件中JSon格式的字符串
  30. /// </param>
  31. procedure setBeanConfig(pvBeanConfig: PAnsiChar); virtual; stdcall;
  32. protected
  33. //获取实例Handle
  34. function getInstanceID: string; stdcall;
  35. //获取窗体对象
  36. function getObject: TObject; stdcall;
  37. procedure showAsMDI; stdcall;
  38. function showAsModal: Integer; stdcall;
  39. procedure showAsNormal(); stdcall;
  40. //关闭和释放窗体
  41. procedure closeForm; stdcall;
  42. protected
  43. procedure FreeObject; stdcall;
  44. public
  45. constructor Create(AOwner: TComponent); override;
  46. destructor Destroy; override;
  47. end;
  48. implementation
  49. constructor TBasePluginForm.Create(AOwner: TComponent);
  50. begin
  51. inherited Create(AOwner);
  52. FInstanceID := CreateClassID;
  53. end;
  54. destructor TBasePluginForm.Destroy;
  55. begin
  56. //通知从主窗体中移除掉本插件
  57. TmBeanMainFormTools.removeFromMainForm(AnsiString(FInstanceID));
  58. //如果共享变量中存在该接口则进行移除(可以提早移除)
  59. TMyBeanFactoryTools.removeObject(AnsiString(FInstanceID));
  60. inherited Destroy;
  61. end;
  62. procedure TBasePluginForm.DoClose(var Action: TCloseAction);
  63. begin
  64. if not (fsModal in self.FFormState) then action := caFree;
  65. inherited DoClose(Action);
  66. end;
  67. function TBasePluginForm.getCaption: PAnsiChar;
  68. begin
  69. __pass := AnsiString(Caption);
  70. Result := PAnsiChar(__pass);
  71. end;
  72. function TBasePluginForm.getInstanceID: string;
  73. begin
  74. Result := FInstanceID;
  75. end;
  76. function TBasePluginForm.getObject: TObject;
  77. begin
  78. Result := Self;
  79. end;
  80. procedure TBasePluginForm.FreeObject;
  81. begin
  82. Self.Free;
  83. end;
  84. procedure TBasePluginForm.setBeanConfig(pvBeanConfig: PAnsiChar);
  85. begin
  86. FBeanConfigStr :=String(AnsiString(pvBeanConfig));
  87. end;
  88. procedure TBasePluginForm.setCaption(pvCaption: PAnsiChar);
  89. begin
  90. self.Caption := String(AnsiString(pvCaption));
  91. end;
  92. procedure TBasePluginForm.showAsMDI;
  93. begin
  94. //让DLL 的Application设置为主程序的Application
  95. //主程序应该把application对象保存到共享对象中,并命名为MainApplication
  96. //在DLL的工程源代码中应该保存原Application,并在卸载DLL前还原
  97. //Application := TmBeanMainFormTools.getMainForm.GetMainApplication;
  98. // self.Owner := Application;
  99. self.FormStyle := fsMDIChild;
  100. self.WindowState := wsMaximized;
  101. self.Show;
  102. end;
  103. function TBasePluginForm.showAsModal: Integer;
  104. begin
  105. Result := ShowModal();
  106. end;
  107. procedure TBasePluginForm.showAsNormal;
  108. begin
  109. self.Show;
  110. end;
  111. { TBasePluginForm }
  112. procedure TBasePluginForm.closeForm;
  113. begin
  114. Self.Close;
  115. end;
  116. end.