释放WebService使用的变量

时间:2012-12-06 11:50:55

标签: web-services delphi delphi-xe2

如何发布WebService正在使用的变量。

我正在使用此表单:

 HttpPrincipal.WSDLLocation: = FrmPrincipal.edtWS.Text;
 HttpPrincipal.Service: = 'CADServicesService'; 
 HttpPrincipal.Port := 'CADServices';     
 Trinity: = HttpPrincipal as CADServices;

当我关闭表单时出现错误,并在我声明此部分时发现:

Trinity: = HttpPrincipal as CADServices;

我认为它会陷入记忆中。

错误如下:

  

“指针无效”   关闭表单时发生错误,OnClose或OnDestroy表单中没有任何事件。

描述:      Trinity : CADServices,      HttpPrincipal is a THTTPRIO,      CADServices is my Unit containing all procedures / functions from WebService.

1 个答案:

答案 0 :(得分:3)

尝试在运行时创建HTTPRIO,而不是使用设计时组件:

function GetCadServices(Addr : String): CadServices;
const
  defSvc  = 'CADServicesService';
  defPrt  = 'CADServices';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  RIO := THTTPRIO.Create(nil)  
  try
    Result := (RIO as CadServices);
    RIO.WSDLLocation := Addr;
    RIO.Service := defSvc;
    RIO.Port := defPrt;
  finally
    if (Result = nil) then
      RIO.Free;
  end;
end;

用法:

Trinity := GetCadServices(FrmPrincipal.edtWS.Text);

如果您使用WSDL导入程序导入WSDL,则会自动为您生成此代码(查看CadServices1单元)