G
gzgchan
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一段 Delphi, 此程序通过[File]-->[New]-->[Data Module],创建。在平时的 Widnwos 窗体下,可以通过函数mySQLConn()得到 MySQL 数据库中的指定数据,运行成功。
但是现在的问题是,我用同样的代码,放在一个新写的 DLL 文件中,调用同一个mySQLConn()函数时就会出错,但此DLL中的其他函数都能正常工作。什么原因。
急,看那位能帮到。
==============================================
unit userListMySQL;
interface
uses
SysUtils, Classes, DBXpress, FMTBcd, DB, SqlExpr;
type
TuserSQLDM = class(TDataModule)
userSQLConn: TSQLConnection;
userSQLSet: TSQLDataSet;
private
{ Private declarations }
public
{ Public declarations }
end;
var
userSQLDB: TuserSQLDM;
function mySQLConn(): string;
implementation
function mySQLConn(): string;
begin
userSQLDB.userSQLConn.ConnectionName:='MySQLConnection';
userSQLDB.userSQLConn.DriverName:='MySQL';
userSQLDB.userSQLConn.GetDriverFunc:='getSQLDriverMYSQL';
userSQLDB.userSQLConn.LibraryName:='dbexpmysql.dll';
userSQLDB.userSQLConn.VendorLib:='libmysql.dll';
userSQLDB.userSQLConn.Params.Clear;
userSQLDB.userSQLConn.Params.add('DriverName=MySQL');
userSQLDB.userSQLConn.Params.add('HostName=xxx.xxx.xxx.xxx');
userSQLDB.userSQLConn.Params.add('Database=database');
userSQLDB.userSQLConn.Params.add('User_Name=user');
userSQLDB.userSQLConn.Params.add('Password=password');
userSQLDB.userSQLConn.Params.add('BlobSize=-1');
userSQLDB.userSQLConn.Params.add('ErrorResourceFile=');
userSQLDB.userSQLConn.Params.add('LocaleCode=0000');
userSQLDB.userSQLConn.KeepConnection:=True;
userSQLDB.userSQLConn.Connected:=True;
userSQLDB.userSQLSet.CommandType:=ctQuery;
userSQLDB.userSQLSet.SQLConnection:=userSQLDB.userSQLConn;
userSQLDB.userSQLSet.CommandText:='select * from userlist';
userSQLDB.userSQLSet.ExecSQL;
result :=userSQLDB.userSQLSet.Fields[3].AsString;
userSQLDB.userSQLSet.Close;
userSQLDB.userSQLConn.Close;
end;
end.
但是现在的问题是,我用同样的代码,放在一个新写的 DLL 文件中,调用同一个mySQLConn()函数时就会出错,但此DLL中的其他函数都能正常工作。什么原因。
急,看那位能帮到。
==============================================
unit userListMySQL;
interface
uses
SysUtils, Classes, DBXpress, FMTBcd, DB, SqlExpr;
type
TuserSQLDM = class(TDataModule)
userSQLConn: TSQLConnection;
userSQLSet: TSQLDataSet;
private
{ Private declarations }
public
{ Public declarations }
end;
var
userSQLDB: TuserSQLDM;
function mySQLConn(): string;
implementation
function mySQLConn(): string;
begin
userSQLDB.userSQLConn.ConnectionName:='MySQLConnection';
userSQLDB.userSQLConn.DriverName:='MySQL';
userSQLDB.userSQLConn.GetDriverFunc:='getSQLDriverMYSQL';
userSQLDB.userSQLConn.LibraryName:='dbexpmysql.dll';
userSQLDB.userSQLConn.VendorLib:='libmysql.dll';
userSQLDB.userSQLConn.Params.Clear;
userSQLDB.userSQLConn.Params.add('DriverName=MySQL');
userSQLDB.userSQLConn.Params.add('HostName=xxx.xxx.xxx.xxx');
userSQLDB.userSQLConn.Params.add('Database=database');
userSQLDB.userSQLConn.Params.add('User_Name=user');
userSQLDB.userSQLConn.Params.add('Password=password');
userSQLDB.userSQLConn.Params.add('BlobSize=-1');
userSQLDB.userSQLConn.Params.add('ErrorResourceFile=');
userSQLDB.userSQLConn.Params.add('LocaleCode=0000');
userSQLDB.userSQLConn.KeepConnection:=True;
userSQLDB.userSQLConn.Connected:=True;
userSQLDB.userSQLSet.CommandType:=ctQuery;
userSQLDB.userSQLSet.SQLConnection:=userSQLDB.userSQLConn;
userSQLDB.userSQLSet.CommandText:='select * from userlist';
userSQLDB.userSQLSet.ExecSQL;
result :=userSQLDB.userSQLSet.Fields[3].AsString;
userSQLDB.userSQLSet.Close;
userSQLDB.userSQLConn.Close;
end;
end.