I'm trying to use COM interface within a thread. From what I have read I have to call CoInitialize/CoUninitialize
in each thread.
While this is working fine:
procedure TThreadedJob.Execute;
begin
CoInitialize(nil);
// some COM stuff
CoUninitialize;
end;
when I move the calls to constructor and destructor:
TThreadedJob = class(TThread)
...
protected
procedure Execute; override;
public
constructor Create;
destructor Destroy; override;
...
constructor TThreadedJob.Create;
begin
inherited Create(True);
CoInitialize(nil);
end;
destructor TThreadedJob.Destroy;
begin
CoUninitialize;
inherited;
end;
procedure TThreadedJob.Execute;
begin
// some COM stuff
end;
I get EOleException: CoInitialize has not been called exception and I have no clue why.