内嵌FMX的插件窗口,效果还是很可以的。退出时,会报错,很诡异啊。
主窗口代码如下
unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, qplugins_vcl_formsvc, qplugins_loader_lib, qstring, qplugins_base, qplugins, qplugins_params, qplugins_vcl_Messages, qplugins_formsvc, Vcl.StdCtrls; type TForm_Main = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form_Main: TForm_Main; implementation {$R *.dfm} // 按钮_FMX窗口 procedure TForm_Main.Button1Click(Sender: TObject); var AFormService: IQFormService; AParam: IQParam; begin // 在这个路径查找服务 if Supports(PluginsManager.ByPath('/Services/Docks/Forms/FMXForm'), IQFormService, AFormService) then begin // 模态显示窗口 // 输出窗口信息 ShowMessage(ServiceSource(AFormService as IQService)); // 模态显示窗口 AFormService.ShowModal(nil, nil); end; end; // 创建 procedure TForm_Main.FormCreate(Sender: TObject); var APath: string; begin ReportMemoryLeaksOnShutdown := True; // 加载同目录的DLL插件 APath := ExtractFilePath(Application.ExeName); PluginsManager.Loaders.Add(TQDLLLoader.Create(APath, '.dll')); // 启动 PluginsManager.Start; end; end.
FMX的DLL插件代码如下
unit Frm_Fmx; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Ani, FMX.Objects, QPlugins, qplugins_fmx_messages, qplugins_formsvc, qplugins_fmx_formsvc, FMX.Edit; type TForm_Fmx = class(TForm) Label1: TLabel; Panel1: TPanel; Image1: TImage; FloatAnimation1: TFloatAnimation; Edit1: TEdit; Edit2: TEdit; private { Private declarations } public { Public declarations } end; var Form_Fmx: TForm_Fmx; implementation {$R *.fmx} { procedure ShowFMXForm; begin // 创建窗口 Form_Fmx := TForm_Fmx.Create(nil); FreeAndNil(Form_Fmx); end; exports ShowFMXForm; } initialization // 注册2个窗体服务 RegisterFormService('/Services/Docks/Forms', 'FMXForm', TForm_Fmx, True); RegisterFormService('/Services/Docks/Forms', 'FMXDock', TForm_Fmx, False).Align := faLeftBottom; finalization // 注销 UnregisterServices('/Services/Docks/Forms', ['FMXForm', 'FMXDock']); end.