P
porsche
Unregistered / Unconfirmed
GUEST, unregistred user!
请问,如何在DLL 编制ADO数据库查询
//--------------------------------库文件
library dbf;
uses
Windows, Messages, SysUtils, Classes, Controls, Db, ADODB, StdCtrls;
function DoTest: pchar; stdcall;
var adoconn: TADOConnection;
query: TAdoquery;
begin
adoconn := TADOConnection.Create(nil);
query := TAdoquery.Create(nil);
try
adoconn.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:/library/Database/DBF.mdb;Persist Security Info=False';
adoconn.LoginPrompt := false;
try
adoconn.Connected := true;
query.Connection := adoconn;
if query.Active then query.Close;
query.SQL.text := 'select StartStation from bus';
try
query.Open;
randomize;
query.MoveBy(random(query.RecordCount));
result := pchar(query.Fields[0].Asstring);
finally
query.Close;
end;
except
adoconn.Connected := false;
end;
finally
adoconn.free;
query.Free;
end;
end;
exports
DoTest;
begin
end.
//--------------------------------
//调用程序
//--------------------------------
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;//, Db, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function DoTestchar;stdcall;external 'dbf.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
caption:=pchar(DoTest);
end;
end.
//--------------------------------
现在我如果在 调用程序 unit1的USES单元中加上 , Db, ADODB;则可以运行,如果去掉则出错
我的意思是在unit1 USES单元中[red]一定不能加上Db, ADODB,[/red]因为这个DLL不是
在delphi下调用的,麻烦大家帮忙看看应该如何写。
//--------------------------------库文件
library dbf;
uses
Windows, Messages, SysUtils, Classes, Controls, Db, ADODB, StdCtrls;
function DoTest: pchar; stdcall;
var adoconn: TADOConnection;
query: TAdoquery;
begin
adoconn := TADOConnection.Create(nil);
query := TAdoquery.Create(nil);
try
adoconn.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:/library/Database/DBF.mdb;Persist Security Info=False';
adoconn.LoginPrompt := false;
try
adoconn.Connected := true;
query.Connection := adoconn;
if query.Active then query.Close;
query.SQL.text := 'select StartStation from bus';
try
query.Open;
randomize;
query.MoveBy(random(query.RecordCount));
result := pchar(query.Fields[0].Asstring);
finally
query.Close;
end;
except
adoconn.Connected := false;
end;
finally
adoconn.free;
query.Free;
end;
end;
exports
DoTest;
begin
end.
//--------------------------------
//调用程序
//--------------------------------
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;//, Db, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function DoTestchar;stdcall;external 'dbf.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
caption:=pchar(DoTest);
end;
end.
//--------------------------------
现在我如果在 调用程序 unit1的USES单元中加上 , Db, ADODB;则可以运行,如果去掉则出错
我的意思是在unit1 USES单元中[red]一定不能加上Db, ADODB,[/red]因为这个DLL不是
在delphi下调用的,麻烦大家帮忙看看应该如何写。