006.Delphi插件之QPlugins,多服务演示
演示效果如下

演示工程,全部就一个文件,代码如下
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,多服务演示的更多相关文章
- 009.Delphi插件之QPlugins,服务的热插拔
这个DEMO用来演示服务的替换,用起来总是怪怪的感觉,效果图如下 代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages, ...
- 008.Delphi插件之QPlugins,服务的两种调用方法
这个QPlugins自带的DEMO,大概的意思就是,创建2个服务类,程序启动的时候注册这2个服务类.点击不同的按钮,使用不同的方法来调用这个服务. 效果界面如下 unit Frm_Main; inte ...
- 010.Delphi插件之QPlugins,遍历服务接口
这个DEMO注意是用来看一个DLL所拥有的全部服务接口 演示效果如下 代码如下: unit Frm_Main; interface uses Winapi.Windows, Winapi.Messag ...
- 012.Delphi插件之QPlugins,多实例内嵌窗口服务
这个DEMO中主要是在DLL中建立了一个IDockableControl类,并在DLL的子类中写了具体的实现方法. 在主程序exe中,找到这个服务,然后调用DLL的内嵌方法,把DLL插件窗口内嵌到主程 ...
- 011.Delphi插件之QPlugins,延时加载服务
这个DEMO是是把DLL插件的相关信息做成了一个配置文件,主程序加载这个配置文件,从而起到延时加载的作用 主程序代码如下 unit Frm_Main; interface uses Winapi.Wi ...
- 013.Delphi插件之QPlugins,模块化代码示例
这个DEMO的是一个定义了一个窗体插件接口,把其他窗口注册到这个窗体插件接口中.主程序运行起来,就遍历一下窗体插件接口,把每个窗体内嵌到对话框中 运行效果如下 主窗口代码如下 unit Frm_Mai ...
- 005.Delphi插件之QPlugins,IQNotify通知
演示的界面如下,拖动滚动条,百分比圆和进度条也是会跟着动的 主程序的代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages ...
- 004.Delphi插件之QPlugins,参数传递
界面如下 插件框架中大量使用了接口的东西,看的眼花缭乱,很多地方只做了申明,具体的实现是在另外的子类. DLL的代码如下 unit ParamTest; interface uses classes, ...
- 015.Delphi插件之QPlugins,FMX插件窗口
内嵌FMX的插件窗口,效果还是很可以的.退出时,会报错,很诡异啊. 主窗口代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messa ...
随机推荐
- 如何优雅的使用python中的代码注释
在编写代码时,确保您的代码易于被其他人理解时很重要的,给变量,函数起合适的名字以及合理的组织代码都是很好的方法. 使用代码注释时增加代码可读性的另一种方便简单且重要的方法! 1.为什么代码注释如此重要 ...
- 2019 深信服 下棋(DFS+回溯)
链接:https://www.nowcoder.com/questionTerminal/a0feb0696e2043a5b3b0779fa861b64a?f=discussion来源:牛客网 8x8 ...
- SPI接口的FLASH
SPI flash W25Qxx: W25Q系列的spiflash.每页(Page)256B,每16个page为一个sector(扇区=4KB),每16个扇区为一个block(块=64KB) W25Q ...
- 在ubuntu中,通过代理服务器访问网络
一.临时设置代理服务的方式 export http_proxy=http://yourproxyaddress:proxyport 这种方式在你退出当前的shell之前,会影响到所有网络命令,包括wg ...
- partition_show , a new version to check partition table status in sqlserver
Dear all: I had put "partition_show" before . but this time it makes faster. partition_sho ...
- Centos7 nginx的目录结构与nginx主配置文件解析
一.nginx的目录结构 [root@node nginx_116]# ls client_body_temp conf fastcgi_temp html logs proxy_temp ...
- 136、Java的内部类
01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; class ...
- 从零开始-建站前的准备之django数据库创建的问题
稍微熟悉了一下django里面对于数据的操作,发现遇见了好多的问题. django对数据的操作是代码式的操作. 一开始在models里面开始为某个表创建参数,像username,password这样的 ...
- 7.12 Varnish体系结构
备注:应用比较小,采用的架构模式 Varnish + 基本业务功能 但是一个问题是所有的资源在一台服务器上,反向代理特别多,缓存数据特别大,导致一台机器资源不够,考虑机器的拆分 Nginx 的反向代 ...
- 如何借助 Python 俘获女孩子芳心?
责编 | 刘静 天气降温,感情却升温了? 上午刚到公司,就收到小Q发来的灵魂拷问: “Q仔!要不然下午请个假!我带你去精神科看看!?”我实在忍不了,脱口而出. 话音未落,前排的运营小花回头看向 ...