演示效果如下

演示工程,全部就一个文件,代码如下

unit Frm_Main;

interface

uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
System.Rtti,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
qstring,
QPlugins,
qplugins_base,
qplugins_params,
Vcl.ExtCtrls; type
TForm_Main = class(TForm)
Panel1: TPanel;
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end; // 继承自TQService服务
TIntAddService = class(TQService)
public
function Execute(AParams: IQParams; AResult: IQParams): Boolean; override; stdcall;
end; // 继承自TQService服务
TFloatAddService = class(TQService)
public
function Execute(AParams: IQParams; AResult: IQParams): Boolean; override; stdcall;
end; var
Form_Main: TForm_Main; implementation {$R *.dfm} // 判断参数类型
function IsIntType(AType: TQParamType): Boolean;
begin
Result := AType in [ptInt8, ptInt16, ptInt32, ptInt64, ptUInt8, ptUInt16,
ptUInt32, ptUInt64];
end; // 判断参数类型
function IsFloatType(AType: TQParamType): Boolean;
begin
Result := AType in [ptFloat4, ptFloat8];
end;
{TFloatAddService} function TFloatAddService.Execute(AParams, AResult: IQParams): Boolean;
begin
// 判断参数类型都是浮点型
if IsFloatType(AParams[].ParamType) and IsFloatType(AParams[].ParamType)
then
begin
// 两个参数相加
AResult.Add('Result', ptFloat8).AsFloat := AParams[].AsFloat +
AParams[].AsFloat;
Result := True;
end
else
Result := False;
end;
{TIntAddService} function TIntAddService.Execute(AParams, AResult: IQParams): Boolean;
begin
// 判断参数类型都是整数型
if IsIntType(AParams[].ParamType) and IsIntType(AParams[].ParamType) then
begin
// 两个参数相加
AResult.Add('Result', ptInt64).AsInt64 := AParams[].AsInt64 +
AParams[].AsInt64;
Result := True;
end
else
begin
Result := False;
end;
end; procedure TForm_Main.Button1Click(Sender: TObject);
var
AServices: IQServices;
AParams, AResult: IQParams;
procedure Calc;
var
I: Integer;
begin
// 注册2个服务,名字分别为TIntAddService和TFloatAddService
for I := to AServices.Count - do
begin
if AServices[I].Execute(AParams, AResult) then
begin
Memo1.Lines.Add('通过服务 ' + AServices[I].Name + ' 计算完成。');
Break;
end;
end;
end; begin
// 创建2个参数
AParams := TQParams.Create;
AResult := TQParams.Create;
// 调用两个整数型相加
AServices := PluginsManager.ByPath('Services/Adds') as IQServices;
AParams.Add('X', ptUInt8).AsInteger := ;
AParams.Add('Y', ptUInt8).AsInteger := ;
Calc;
Memo1.Lines.Add(' 计算表达式 100+200=' + IntToStr(AResult[].AsInt64));
AParams.Clear;
AResult.Clear;
// 调用两个浮点型相加
AParams.Add('X', ptFloat8).AsFloat := 100.3;
AParams.Add('Y', ptFloat8).AsFloat := 20.05;
Calc;
Memo1.Lines.Add(' 计算表达式 100.3+20.05=' + FloatToStr(AResult[].AsFloat));
end; // 创建
procedure TForm_Main.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown := True;
// 注册2个服务,名字分别为TIntAddService和TFloatAddService
RegisterServices('/Services/Adds', [TIntAddService.Create(NewId, 'AddInt'), TFloatAddService.Create
(NewId, 'AddFloat')]);
end; end.

006.Delphi插件之QPlugins,多服务演示的更多相关文章

  1. 009.Delphi插件之QPlugins,服务的热插拔

    这个DEMO用来演示服务的替换,用起来总是怪怪的感觉,效果图如下 代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages, ...

  2. 008.Delphi插件之QPlugins,服务的两种调用方法

    这个QPlugins自带的DEMO,大概的意思就是,创建2个服务类,程序启动的时候注册这2个服务类.点击不同的按钮,使用不同的方法来调用这个服务. 效果界面如下 unit Frm_Main; inte ...

  3. 010.Delphi插件之QPlugins,遍历服务接口

    这个DEMO注意是用来看一个DLL所拥有的全部服务接口 演示效果如下 代码如下: unit Frm_Main; interface uses Winapi.Windows, Winapi.Messag ...

  4. 012.Delphi插件之QPlugins,多实例内嵌窗口服务

    这个DEMO中主要是在DLL中建立了一个IDockableControl类,并在DLL的子类中写了具体的实现方法. 在主程序exe中,找到这个服务,然后调用DLL的内嵌方法,把DLL插件窗口内嵌到主程 ...

  5. 011.Delphi插件之QPlugins,延时加载服务

    这个DEMO是是把DLL插件的相关信息做成了一个配置文件,主程序加载这个配置文件,从而起到延时加载的作用 主程序代码如下 unit Frm_Main; interface uses Winapi.Wi ...

  6. 013.Delphi插件之QPlugins,模块化代码示例

    这个DEMO的是一个定义了一个窗体插件接口,把其他窗口注册到这个窗体插件接口中.主程序运行起来,就遍历一下窗体插件接口,把每个窗体内嵌到对话框中 运行效果如下 主窗口代码如下 unit Frm_Mai ...

  7. 005.Delphi插件之QPlugins,IQNotify通知

    演示的界面如下,拖动滚动条,百分比圆和进度条也是会跟着动的 主程序的代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages ...

  8. 004.Delphi插件之QPlugins,参数传递

    界面如下 插件框架中大量使用了接口的东西,看的眼花缭乱,很多地方只做了申明,具体的实现是在另外的子类. DLL的代码如下 unit ParamTest; interface uses classes, ...

  9. 015.Delphi插件之QPlugins,FMX插件窗口

    内嵌FMX的插件窗口,效果还是很可以的.退出时,会报错,很诡异啊. 主窗口代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messa ...

随机推荐

  1. SQL的四种连接(内连接,外连接)

    一,内连接(inner join) 内连接(INNER JOIN):分显式的和隐式的,返回连接表中符合连接条件和查询条件的数据行.(所谓的连接表就是数据库在做查询形成的中间表). 1.隐式的内连接 没 ...

  2. 4 Action的3种编写方式,pojo,实现和继承(推荐)

    Action的访问: 1 Action类是pojo(Plain Ordinary Java Object):简单Java对象,无接口,无继承.例如上篇文章中只创建了public String exec ...

  3. PPT页面动画制作

    因为武汉新型冠状肺炎的影响,今年自从2月3号开工以来,就在家办公.我的任务刚好是安排做PPT,虽说之前做过PPT,但大家都知道,作为一个IT测试工程师,更多的是测试工作,只有在培训,还有年终汇报的时候 ...

  4. Nodejs回调加超时限制两种实现方法

    odejs回调加超时限制两种实现方法 Nodejs下的IO操作都是异步的,有时候异步请求返回太慢,不想无限等待回调怎么办呢?我们可以给回调函数加一个超时限制,到一定时间还没有回调就表示失败,继续后面的 ...

  5. Linux进程管理(一)

    目录 Linux进程管理(一) 参考 pstree命令 pidof命令 pmap命令 pwdx命令 ps命令 nice调优 发送信号 Linux进程管理(一)

  6. 郁闷的 IE6/7/8 所遇兼容问题

    IE6,7只支持inline元素设置为inline-block,但不支持block元素转换成inline-block,所以非inline元素在IE6,7下要转换成inline-block,需先转换成i ...

  7. centos7搭建svn服务器及客户端设置

    centos7搭建svn服务器及客户端设置 centos7貌似预装了svn服务(有待确认),因此我们直接启动该服务即可 一.svn服务端配置(服务器IP假设为192.168.100.1) 步骤1:创建 ...

  8. 吴裕雄--天生自然HADOOP学习笔记:使用yum安装更新软件

    实验目的 了解yum的原理及配置 学习软件的更新与安装 学习源代码编译安装 实验原理 1.编译安装 前面我们讲到了安装软件的方式,因为linux是开放源码的,我们可以直接获得源码,自己编译安装.例如: ...

  9. java并发队列

    阻塞队列 常见的阻塞队列有ArrayBlockingQueue,LinkedBlockingDeque,LinkedBlockingQueue,这些队列有界且可以阻塞线程 ArrayBlockingQ ...

  10. map的查询和修改方法

    1:map查询的方法 package com.cn.util; import java.util.ArrayList; import java.util.HashMap; import java.ut ...