主程序用TUniConnection连接数据库,调用dll时把TUniConnection作为参数传给dll。
结果数据控件OPEN时出错。(dll中有无 TOracleUniProvider都一样,dll作为单独程序运行没问题)。程序原来用ADO控件是没问题的,换uniDAC就不行了。UNIDAC
结果数据控件OPEN时出错。(dll中有无 TOracleUniProvider都一样,dll作为单独程序运行没问题)。程序原来用ADO控件是没问题的,换uniDAC就不行了。UNIDAC
用: ActiveX.CoInitialize(nil); //对ActiveX 初始化
begin
try
CoInitialize(nil);
if cdForm=nil then
cdForm:=TcdForm.Create(nil);
con1:=conn;
if not con1.Connected then
con1.Connected:=True; //
account:=saccount;
cdForm.ShowModal;
finally
con1.Connected:=False;
CoUninitialize();
if cdForm<>nil then
begin
cdForm.Free;
cdForm:=nil;
end;
end;
end;
DLL内部的窗体开发编译的时候,数据集一定要关闭。在mydac下,有个MyServices.pas单,找到
procedure TCustomMyDataSetService.FillFieldDescs(out FieldDescs
: TFieldDescArray; FillKeyFieldDescs, ForceUseAllFields: boolean);begin
FieldDescs := nil; if (FDataSet.Fields.Count = 0) or (GetIRecordSet.Fields.Count = 0) then
Exit; for i := 0 to FDataSet.Fields.Count - 1 do
begin
Field := FDataSet.Fields[i];
if Field.FieldKind = fkData then
begin
if FDataSet.GetFieldDesc(Field) is TMySQLFieldDesc then // 这是修改的
FieldDesc := FDataSet.GetFieldDesc(Field) as TMySQLFieldDesc; IsNeedProcessField := ForceUseAllFields or // (Self is TCustomMyTable) or
(FieldDesc.TableInfo = UpdatingTableInfo) or
((FieldDesc.TableInfo = nil) and
not FDataSet.Options.SetFieldsReadOnly); if IsNeedProcessField then
ProcessField(FieldDesc);
end;
end; if FillKeyFieldDescs then
CheckPrimaryKeys;
end;
而不能直接赋值,不然会出Invalid class typecast的问题。
这样每个dll都有一个链接,增加数据库的连接数,没啥意思了。