由于请求webservice的时候比较费时,而且我需要每隔几秒钟请求一次,这样的话,主界面基本上就是一卡一卡的,所以就考虑把调用webservice的代码放到一个线程里,免得影响用户操作。我这样做为什么虽然可以正常运行,但是调试时后会报错:
type
  TMainForm = class(TForm)
省略
  private
    { Private declarations }
  public
     end;type
    TMyThread =class(TThread)
    HTTPRIO1: THTTPRIO;//《--------------我把mainform中的这个移到这里了。
private
    FFlag:Integer;
    procedure Getws;
protected
    procedure Execute ; override;
public
    constructor Create(aFlag:Integer);
end;
省略
procedure TMyThread.Getws;
var
  WsObj,WsObj2:HosServicePortType;
  i:Integer;
  btimestr:string;
begin
  try
    CoInitialize(Nil);
    WsObj:=HTTPRIO1 as HosServicePortType;//这样初始化
    WsArray:=WsObj.getBook(hosid,FormatDateTime('yyyymmdd',d1));//连接webservice并查询,这句错误
  finally
    CoUninitialize;
  end;
在调试的时候报错:First chance exception at $7C812AFB. Exception class EAccessViolation with message 'Access violation at address 0066B99B in module 'HosClient.exe'. Read of address 00000000'. Process HosClient.exe (3904)刚学习线程,请多指教。