how to pass interface type to procedure

浪子不回头ぞ 提交于 2019-12-12 11:08:09

问题


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

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;

回答1:


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.



来源:https://stackoverflow.com/questions/55136990/how-to-pass-interface-type-to-procedure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!