如何将接口类型传递给过程 [英] how to pass interface type to procedure

查看:74
本文介绍了如何将接口类型传递给过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将接口类型传递给over过程参数?

how to I pass interface type to over procedure parameter ?

type
    Hello_PortType = interface(ISoapInvokable)
      ['{243CBD89-8766-F19D-38DF-427D7A02EAEE}']
        function GetDeneme(s: string): string;
      end;

SoapCall(Hello_PortType , 'http://localhost:8080/wsdl/ITDeneme');

然后如何通过saopcall方法变量获取TypeInfo?

then how to get TypeInfo using with saopcall method variable ?

function TLib.SoapCall(Intf: Variant; Addr: string): ISoapInvokable;
var
  RIO: THTTPRIO;
begin

  InvRegistry.RegisterInterface(TypeInfo(Intf), 'urn:DenemeIntf-IDeneme', ''); //-- type info doesn't work with variant
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Intf), 'GetDeneme');

  Result := nil;
  if Addr = '' then
    exit();

  RIO := THTTPRIO.Create(nil);
  try
    Result := RIO as ISoapInvokable;
    RIO.URL := Addr;
  finally
    if (Result = nil) then
      RIO.Free;
  end;
end;


推荐答案

您需要指定 TypeInfo()指针,而不是接口类型。

You need to specify the TypeInfo() pointer, not the interface type.

SoapCall(TypeInfo(Hello_PortType) , 'http://localhost:8080/wsdl/ITDeneme');

function TLib.SoapCall(TypInfo: pointer; Addr: string): ISoapInvokable;
var
  RIO: THTTPRIO;
begin

  InvRegistry.RegisterInterface(TypInfo, 'urn:DenemeIntf-IDeneme', '');
  InvRegistry.RegisterDefaultSOAPAction(TypInfo, 'GetDeneme');
...

在此不要使用变体-它不会产生任何变化从某种意义上说,因为您期望的是接口类型,而不是接口实例。

Don't use a variant here - it doesn't make any sense, since you expect an interface type, not an interface instance.

这篇关于如何将接口类型传递给过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆