【发布时间】:2016-04-20 07:21:06
【问题描述】:
我正在尝试理解TVirtualInterface 类。
{$APPTYPE CONSOLE}
uses
SysUtils, Rtti;
type
ISpecificInterface = interface(IInvokable)
['{281D8B97-397E-430A-895A-9CA4E1F5FB5F}']
procedure SpecificProcedure;
end;
procedure AProcedure(Method: TRttiMethod; const Args: TArray<TValue>;
out Result: TValue);
begin
Writeln(Method.ToString);
end;
var
ISpecificInterfaceInstance: ISpecificInterface;
begin
ISpecificInterfaceInstance := TVirtualInterface.Create
(TypeInfo(ISpecificInterface), AProcedure) as ISpecificInterface;
ISpecificInterfaceInstance.SpecificProcedure;
end. // TVirtualInterface ref. counter is decremented
在运行时实现接口有什么好处?
空间有什么用?
【问题讨论】:
-
docs 说:“TVirtualInterface 的主要应用领域是 SOAP 消息传递。SOAP 服务器声明了具有特定功能的服务。WSDL 导入器创建了一个 Delphi 接口来“镜像”服务器服务。在客户端,在运行时创建一个类,它实现了反映服务器服务的Delphi接口(TVirtualInterface),当调用这个类的一个方法时,调用被封装在一个SOAP信封中,发送到服务器,解码,并将结果发送回 Delphi 客户端。”