演示效果如下

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

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. C语言的变量存储方式和生存期

    2020.2.28日,封城一个多月了,紧邻毕业期,我在家抽空学习一下C. 看到了变量的存储方式和生存期这一章节,下面就是我整理的内容 下面是用于理解静态局部变量这个概念所写的代码,主要是需要分析一下函 ...

  2. hadoop程序理解

    1.利用hadoop的API写程序 驱动程序中利用hadoop的API,获取配置,默认会根据HADOOP_HOME环境变量指定的HADOOP主目录下/etc/hadoop加载配置文件 2.启动利用 - ...

  3. 吴裕雄--天生自然数据结构与算法:java代码实现常用数据结构——链表Linked List

    class Node{ // 定义节点类 private String data ; // 保存节点内容 private Node next ; // 表示保存下一个节点 public Node(St ...

  4. 搭建python虚拟环境virtualenv

    virtualenv 是一个创建隔离Python环境的工具,创建虚拟环境运行,达到节省本地运行空间的目的. 安装vitualenv # pip install virtualenv 创建一个虚拟环境( ...

  5. Java如何实现序列化,有什么意义?

    1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态,并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存Object States, 但是Java给你提供一种应该 ...

  6. CDC学习

    最近在建立CDC环境,在网上看到一些不错的学习链接,粘贴如下: 1.https://blog.csdn.net/u011729865/article/details/52931366 属于https: ...

  7. Linux centos VMware Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理

    一.Nginx防盗链 配置如下,可以和上面的配置结合起来 location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|x ...

  8. HIHOcoder编程总结

    [Offer收割]编程练习赛44 对于第一题题目1 : 扫雷游戏,首先要想清楚思路,虽然是暴力算法,但是这八个方向要自己把坐标写正确,不要慌乱,自己写的时候就写错了一个,第二个就是判断的时候,j + ...

  9. C++中文件的读取操作,如何读取多行数据,如何一个一个的读取数据

    练习8.1:编写函数.接受一个istream&参数,返回值类型也是istream&.此函数必须从给定流中读取数据,直至遇到文件结束标识时停止. #include <iostrea ...

  10. 【动画演示】:JS 作用域链不在话下

    作者:Lydia Hallie译者:前端小智来源:dev 点赞再看,养成习惯 本文 GitHub https://github.com/qq44924588... 上已经收录,更多往期高赞文章的分类, ...