G
gxsh
Unregistered / Unconfirmed
GUEST, unregistred user!
我在Delphi中做了一个窗体放了一个ADOQuery,一个DataSource等其它控件,编译成一个DLL,
ADOQuery从外部接受连接字符串及SQL字符串,并连接到指定数据库查询相应的记录,
在Delphi调用通过,在VB中调用时总是提示“无效的连接或连接字符串”,然后出现DLL中的窗体及另一个提示:
“ADOQuery1 不能在一个已关闭的数据集上执行该操作”后退出,谁能帮我?
//DLL 主代码
unit main;
interface
uses
forms,Windows,Db, ADODB, Graphics, Classes, Controls,
StdCtrls, ExtCtrls,ReportControl;
type
TfrmRepView = class(TForm)
ReportRunTime1: TReportRunTime;
Label1: TLabel;
Image1: TImage;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
procedure FormActivate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
frmRepView: TfrmRepView;
ADOConn:WideString;
ADOSQL:String;
function cRepView (connChar;SQLChar):Boolean;stdcall;
implementation
{$R *.DFM}
function cRepView (connChar;SQLChar):Boolean;
begin
ADOConn:= conn;
ADOSQL:=SQL;
frmRepView:=TfrmRepView.Create(nil);
try
Result:=(frmRepView.ShowModal=mrOK);
finally
frmRepView.Free;
end;
end;
procedure TfrmRepView.FormActivate(Sender: TObject);
begin
Application.ProcessMessages;
ReportRunTime1.SetDataset('d1',ADOQuery1);
ReportRunTime1.printpreview(true);
end;
procedure TfrmRepView.FormPaint(Sender: TObject);
begin
close;
end;
procedure TfrmRepView.FormCreate(Sender: TObject);
begin
with ADOQuery1 do
begin
SQL.Clear;
Close;
ConnectionString:= ADOConn;
SQL.Text:= ADOSQL;
ADOQuery1.Open;
end;
With ReportRunTime1 Do
begin
setdataset('d1',ADOQuery1);
reportfile:='c:/temp/meitong.ept';
enableedit:=true;
end;
end;
我在VB中是这样调用的:
'声名部分
Private Declare Function cRepView Lib "cRepView.dll" (ByVal conn As String, ByVal SQL As String)
'调用
Call cRepView("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Temp/nanwei.mdb;Persist Security Info=False", _
"Select * From aa")
ADOQuery从外部接受连接字符串及SQL字符串,并连接到指定数据库查询相应的记录,
在Delphi调用通过,在VB中调用时总是提示“无效的连接或连接字符串”,然后出现DLL中的窗体及另一个提示:
“ADOQuery1 不能在一个已关闭的数据集上执行该操作”后退出,谁能帮我?
//DLL 主代码
unit main;
interface
uses
forms,Windows,Db, ADODB, Graphics, Classes, Controls,
StdCtrls, ExtCtrls,ReportControl;
type
TfrmRepView = class(TForm)
ReportRunTime1: TReportRunTime;
Label1: TLabel;
Image1: TImage;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
procedure FormActivate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
frmRepView: TfrmRepView;
ADOConn:WideString;
ADOSQL:String;
function cRepView (connChar;SQLChar):Boolean;stdcall;
implementation
{$R *.DFM}
function cRepView (connChar;SQLChar):Boolean;
begin
ADOConn:= conn;
ADOSQL:=SQL;
frmRepView:=TfrmRepView.Create(nil);
try
Result:=(frmRepView.ShowModal=mrOK);
finally
frmRepView.Free;
end;
end;
procedure TfrmRepView.FormActivate(Sender: TObject);
begin
Application.ProcessMessages;
ReportRunTime1.SetDataset('d1',ADOQuery1);
ReportRunTime1.printpreview(true);
end;
procedure TfrmRepView.FormPaint(Sender: TObject);
begin
close;
end;
procedure TfrmRepView.FormCreate(Sender: TObject);
begin
with ADOQuery1 do
begin
SQL.Clear;
Close;
ConnectionString:= ADOConn;
SQL.Text:= ADOSQL;
ADOQuery1.Open;
end;
With ReportRunTime1 Do
begin
setdataset('d1',ADOQuery1);
reportfile:='c:/temp/meitong.ept';
enableedit:=true;
end;
end;
我在VB中是这样调用的:
'声名部分
Private Declare Function cRepView Lib "cRepView.dll" (ByVal conn As String, ByVal SQL As String)
'调用
Call cRepView("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Temp/nanwei.mdb;Persist Security Info=False", _
"Select * From aa")