D
Dbjam
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾:
我写了一个dll,在dll中要操作数据库,有一exe文件调用这个dll,exe文件退出时内存出错。
程序如下.
//--------------------------------------------- dll
library trans;
uses
SysUtils,
Classes,
windows,
DbTables;
function InitDB(Driver,Service,Database,UserName,PasswordChar;Check:Boolean):Bool;Stdcall;
var
__db:tdatabase;
begin
result:=false;
__db:= TDatabase.Create(nil);
__db.DatabaseName := 'TransTest';
__db.DriverName := Driver;
__db.params.clear;
__db.Params.Add('server name='+Service);
__db.Params.Add('database name='+Database);
__db.Params.Add('user name='+Username);
__db.Params.Add('password='+password);
__db.LoginPrompt := false;
try
__db.Open;
// / 如果注释掉这两行,主程序退出不会出错
__db.close;
// /
result:=true;
except
end;
__db.free;
end;
end;
exports
InitDB index 2;
{$R *.RES}
begin
end.
//------------------------------------------ exe
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function InitDB(Driver,
Service,
Database,
UserName,
PasswordChar;
Check:Boolean
):Bool;Stdcall;external 'dbtest.dll';
var
Form1: TForm1;
implementation
uses
registry,
DbTables;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if InitDB('informix','onmcis_online','trans','informix','informix',true) then
showmessage('connect ok');
end;
end.
我写了一个dll,在dll中要操作数据库,有一exe文件调用这个dll,exe文件退出时内存出错。
程序如下.
//--------------------------------------------- dll
library trans;
uses
SysUtils,
Classes,
windows,
DbTables;
function InitDB(Driver,Service,Database,UserName,PasswordChar;Check:Boolean):Bool;Stdcall;
var
__db:tdatabase;
begin
result:=false;
__db:= TDatabase.Create(nil);
__db.DatabaseName := 'TransTest';
__db.DriverName := Driver;
__db.params.clear;
__db.Params.Add('server name='+Service);
__db.Params.Add('database name='+Database);
__db.Params.Add('user name='+Username);
__db.Params.Add('password='+password);
__db.LoginPrompt := false;
try
__db.Open;
// / 如果注释掉这两行,主程序退出不会出错
__db.close;
// /
result:=true;
except
end;
__db.free;
end;
end;
exports
InitDB index 2;
{$R *.RES}
begin
end.
//------------------------------------------ exe
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function InitDB(Driver,
Service,
Database,
UserName,
PasswordChar;
Check:Boolean
):Bool;Stdcall;external 'dbtest.dll';
var
Form1: TForm1;
implementation
uses
registry,
DbTables;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if InitDB('informix','onmcis_online','trans','informix','informix',true) then
showmessage('connect ok');
end;
end.