uBasePluginForm.pas 2.8 KB

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