【问题标题】:how to pass interface type to procedure如何将接口类型传递给过程
【发布时间】:2019-03-13 08:04:46
【问题描述】:

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

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 呢?

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;

【问题讨论】:

  • 我猜你的代码不会编译。 Hello_PortType 是接口类型,不是接口实例,所以不能转换成变体。

标签: delphi interface


【解决方案1】:

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

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');
...

不要在此处使用变体 - 这没有任何意义,因为您需要的是接口类型,而不是接口实例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多