CoInitialize(nil);函数找到了,但依然出现提示: Project aa1.exe raised exception class EOleException with message '标记没有引用存储'. Process stopped. Use Step or Run to continue.’ 不知为何?以下是create方法: constructor TThdReadWData.Create(adods : TAdoDataSet; xuhao : integer); begin dbs := adods; No := xuhao; CoInitialize(nil); inherited Create(false);end;
多线程好象要每个连接用单独的Session和DatabaseName安全些。
custquery.active:=true or custquery.open
constructor TThdReadWData.Create(adods : TAdoDataSet; xuhao : integer); begin inherited Create(false); dbs := adods; No := xuhao; CoInitialize(nil); resume;-----------------------------! end;
以上代码也没效果,依然出现提示: Project aa1.exe raised exception class EOleException with message '标记没有引用存储'. Process stopped. Use Step or Run to continue.’
你线程的cteate在哪里?我怎么没有找到?
你在TThdReadWData中定义了一个dbs : TADODataset但是你用dbs的时候,为什么不Create呢?
// ADO 的初始化
CoInitialize(Nil);在析构函数(Destroy)中加:
// ADO 的释放
CoUninitialize;即可。
Project aa1.exe raised exception class EOleException with message '标记没有引用存储'.
Process stopped. Use Step or Run to continue.’
不知为何?以下是create方法:
constructor TThdReadWData.Create(adods : TAdoDataSet; xuhao : integer);
begin
dbs := adods;
No := xuhao;
CoInitialize(nil);
inherited Create(false);end;
or
custquery.open
begin
inherited Create(false);
dbs := adods;
No := xuhao;
CoInitialize(nil);
resume;-----------------------------! end;
Project aa1.exe raised exception class EOleException with message '标记没有引用存储'.
Process stopped. Use Step or Run to continue.’
否则就要用Synchronize
不过建议你还是重新创建DataSet.
确是需要
CoInitialize(Nil);
// ......这儿你动态创建Adoconnection
// ......数据库操作........
CoUninitialize;
但要注意的是,这两个函数是要放在新线程执行中。也就是在
线程对象的execute()方法中。
如果只是加在线程对象的创建方法中,其实还是加在主线程中,并没有
起到作用。
我个人认为是建立了Com对象的套间,这是Com对象在多线程访问的时候必须的,Access是不是支持多线程的并发操作,我不太清楚。
CoInitialize初始化你的ActiveX对象ADO(uses Activex)
使用完之后一定要调用CoUninitialize释放Activex资源。
var
count : integer;
dirs, s : string;
begin
CoInitialize(Nil); sleep(10000); //Just delay, no use
dbs.Open;
dbs.First;
count := 0;
while not dbs.Eof do
begin
inc(count);
data[No, 1, count] := dbs.fieldByName('BZJS').asfloat;
data[No, 2, count] := dbs.fieldByName('CZJS').asfloat;
//....
dbs.Next;
end;
dbs.Close;
ddline[No] := count;
Application.MessageBox(PChar('number '+ inttostr(No) + 'finished '), '',0) ; CoUninitialize;
end;procedure TMultiRead.execute;
var
trwds : array[1..WellNo] of TThdReadWData;
i : integer;
s ,dirs: string;
begin
for i:=1 to WellNo do
begin
dirs := ExtractFilePath(Application.ExeName);
s := dirs + 'File' + IntTostr(i) + '.mdb'; ados[i].ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+s+';Persist Security Info=False' ; ados[i].CommandType := cmdTable;
ados[i].CommandText := 'DepthData';
trwds[i] := TThdReadWData.Create(true); trwds[i].No := i;
trwds[i].dbs := ados[i];
end;
for i:=1 to WellNo do
trwds[i].Resume;
end;