如何将接口类型传递给over过程参数?
type
Hello_PortType = interface(ISoapInvokable)
['{243CBD89-8766-F19D-38DF-427D7A02EAEE}']
function GetDeneme(s: string): string;
end;
SoapCall(Hello_PortType , 'http://localhost:8080/wsdl/ITDeneme');
Run Code Online (Sandbox Code Playgroud)
那么如何使用带有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;
Run Code Online (Sandbox Code Playgroud)
您需要指定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');
...
Run Code Online (Sandbox Code Playgroud)
不要在这里使用变体 - 它没有任何意义,因为您期望的是接口类型,而不是接口实例。