在Delphi  多线程中出现“尚未调用CoInitialize错误”的解决方法

解决方法如下:

 

function  TMyThread.ExecTimer: Boolean;
begin
  Result := False ;
  FMyThreadExecfinish := False;
  Screen.Cursor := crHourGlass;
  CoInitialize(nil); // 一定要加上此行代码
  try
    TranspondClientBaseData_factory1(HTTPRIOLeExp, HTTPRIONC, LogStrings);
    Sleep(1000);
    TranspondPersonBaseData_factory1(HTTPRIOLeExp, HTTPRIONC, LogStrings);
    Sleep(1000);
    TranspondDeptBaseData_factory1(HTTPRIOLeExp, HTTPRIONC, LogStrings);
  finally
    Result := True;
    FMyThreadExecfinish := True;
    Screen.Cursor := crDefault;
    CoUninitialize;// 一定要加上此行代码
  end;

end;