Z
zzhdi
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个Dll,这个dll通过bde连接Sqlsever2000。代码如下:
library wlgl;
uses
SysUtils, Classes, dm in 'dm.pas' {Dmfm: TDataModule};
Exports
ConnectServer;
{$R *.res}
begin
end.
unit dm;
interface
uses
SysUtils, Classes, DB, DBTables;
type
TDmfm = class(TDataModule)
Database1: TDatabase;
private
{ Private declarations }
public
{ Public declarations }
end;
function ConnectServer(ConnecterNameChar;PasswordChar):Boolean; stdcall;
var
Dmfm: TDmfm=nil;
implementation
uses forms;
{$R *.dfm}
function ConnectServer(ConnecterNameChar;PasswordChar):Boolean;
begin
if dmfm=nil then Dmfm:=TDmfm.Create(application);
with dmfm.Database1 do
begin
if Connected then Connected:=false;
Params.Clear;
Params.Add('USER NAME='+ConnecterName);
params.Add('Password='+Password);
LoginPrompt:=false;
Connected:=true;
Result:=Connected;
end;
end;
调用这个Dll的程序部分代码如下:
unit mainform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tmainfrm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
function ConnectServer(ConnecterNameChar;PasswordChar):Boolean; stdcall;external 'wlgl.dll';
var
mainfrm: Tmainfrm;
implementation
{$R *.dfm}
procedure Tmainfrm.Button1Click(Sender: TObject);
begin
if ConnectServer('sa','sa') then showmessage('ok');
end;
end.
我点击Button1后关闭这个程序时,出错。我用 动态链接dll 的方式无错,但反映迟钝。我把dll中的
connected赋值false也无错。我把数据库改为Delphi6 自带的DBDemos数据库,无错。
library wlgl;
uses
SysUtils, Classes, dm in 'dm.pas' {Dmfm: TDataModule};
Exports
ConnectServer;
{$R *.res}
begin
end.
unit dm;
interface
uses
SysUtils, Classes, DB, DBTables;
type
TDmfm = class(TDataModule)
Database1: TDatabase;
private
{ Private declarations }
public
{ Public declarations }
end;
function ConnectServer(ConnecterNameChar;PasswordChar):Boolean; stdcall;
var
Dmfm: TDmfm=nil;
implementation
uses forms;
{$R *.dfm}
function ConnectServer(ConnecterNameChar;PasswordChar):Boolean;
begin
if dmfm=nil then Dmfm:=TDmfm.Create(application);
with dmfm.Database1 do
begin
if Connected then Connected:=false;
Params.Clear;
Params.Add('USER NAME='+ConnecterName);
params.Add('Password='+Password);
LoginPrompt:=false;
Connected:=true;
Result:=Connected;
end;
end;
调用这个Dll的程序部分代码如下:
unit mainform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tmainfrm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
function ConnectServer(ConnecterNameChar;PasswordChar):Boolean; stdcall;external 'wlgl.dll';
var
mainfrm: Tmainfrm;
implementation
{$R *.dfm}
procedure Tmainfrm.Button1Click(Sender: TObject);
begin
if ConnectServer('sa','sa') then showmessage('ok');
end;
end.
我点击Button1后关闭这个程序时,出错。我用 动态链接dll 的方式无错,但反映迟钝。我把dll中的
connected赋值false也无错。我把数据库改为Delphi6 自带的DBDemos数据库,无错。