那些窗口中有些TABLE、QUERY或存储过程,但无一例外的需要跟BDE连接(暂时不想
用ADO或MIDAS来连接),我不想每个窗口上都放一个DATABASE控件,与BDE连的话又要
输入登录数据库的对话框,所以我想能否通过主程序给它传递一个参数让它跟主程序
中的DATABASE连接,或另外做一个数据库连接的DLL,让所有调用者共享该连接,哪位能
帮我?
38 个解决方案
#1
可以,传一个TTable或者TQuery类型的参数不OK了?
或者传一个TDatabase参数,在dll中做好连接等设置。
或者传一个TDatabase参数,在dll中做好连接等设置。
#2
在调用dll时将应用程序的参数赋值给dll。
#3
有例子吗,我也想知道
#4
我今天中午还在思这个问题,能不能在一个DLL中使不同程序共享一个对共享一个对象的变量和方法。谁有这方面的经验,来交流交流
#5
我曾经试过,会报错
#6
我等米下锅
#7
用文件印射好你很难,用DDE又好像不可能。
谁能实现请告知,好想知道
谁能实现请告知,好想知道
#8
因为连接的是SQL的数据库,所以有数据库登录对话框
我在DLL中的那些过程是把Application作为参数传进去的
procedure showform1(MainApp:TApplication);stdcall;export;
var
form1: form1;
begin
if not Assigned(DllApp) then
begin
DllApp := Application;
Application := MainApp;
end;
try
form1:= Tform1.Create(Application);
form1.Show();
except
form1.Free();
end;
end;
我在DLL中的那些过程是把Application作为参数传进去的
procedure showform1(MainApp:TApplication);stdcall;export;
var
form1: form1;
begin
if not Assigned(DllApp) then
begin
DllApp := Application;
Application := MainApp;
end;
try
form1:= Tform1.Create(Application);
form1.Show();
except
form1.Free();
end;
end;
#9
传参数时在我退出应用时会死掉
#10
我在线等候回答
#11
我等,我等......
#12
我已经献出我能给的最高分了
#13
帮你up
#14
I WAIT YOUR ANSWER
#15
答案在何方?
#16
我曾经做过,.dll包含一个login窗体(用ado连接),调用都没问题,只是关闭应用程序时,提示'kernel32.dll'出错,不知为什么
#17
怎么回答这么少呢?
#18
我也想知道不用重新联接TDATABASE就能完成,以下是我在工程中应用的DLL例子部份,但每个FROM都需重定义TDATABASE
library user;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
un_changepass in 'un_changepass.pas' {frm_ChangePass},
un_command in 'un_command.pas',
un_userlogin in 'un_userlogin.pas' {frm_UserLogin},
un_about in 'un_about.pas' {frm_About},
un_Crypt32 in '..\公用声明\un_Crypt32.pas',
un_dbtools in '..\公用声明\un_dbtools.pas';
{$R *.RES}
exports
MSNA_CertifyIsRunToCurrentComputer name 'MSNA_CertifyIsRunToCurrentComputer', //是否可以运行
MSNA_CertifyUserLogin name 'MSNA_CertifyUserLogin', //验证登录
MSNA_ChangePassWord name 'MSNA_ChangePassWord', //改变密码
MNSA_ShowApplicationAboutMessage name 'MNSA_ShowApplicationAboutMessage', //显示关于窗口
MSNA_GetCurrentComputerIPAddress name 'MSNA_GetCurrentComputerIPAddress'; //取得当前计算机IP地址
begin
end.
{=======================================================================
// Application:
// Unit Function:
// 用户登录验证
// Author:alin
// DateTime:2001.09.27
// Change:
// DateTime:
========================================================================}
unit un_userlogin;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, jpeg,dbtables, Db, Grids, DBGrids, DBCtrls;
type
Tfrm_UserLogin = class(TForm)
Image1: TImage;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
e_PassWord: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
dblcb_User: TDBLookupComboBox;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_UserLogin: Tfrm_UserLogin;
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
implementation
uses un_command, un_Crypt32, un_dbtools;
{$R *.DFM}
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
var
IPAddr:PChar;
EnPassWord:String;
DataBase:TDataBase;
sql_Dll:TQuery;
ds_UserList:TDataSource;
Begin
Result :=False;
Application.Handle :=aHandle;
IPAddr :=StrAlloc(30);
MSNA_GetCurrentComputerIPAddress(IPAddr);
frm_UserLogin:=Tfrm_UserLogin.Create(Application);
DataBase:=TDataBase.Create(frm_UserLogin);
sql_Dll:=TQuery.Create(frm_UserLogin);
ds_UserList:=TDataSource.Create(frm_UserLogin);
ds_UserList.DataSet :=sql_Dll;
DataBase.DatabaseName :='DLL_DATA';
DataBase.LoginPrompt :=False;
sql_Dll.DatabaseName :=Database.DatabaseName;
with frm_UserLogin do
Begin
Try
dblcb_User.ListSource :=ds_UserList;
ConnectDataBase(DataBase);
sql_Dll.Close;
sql_Dll.SQL.Clear;
sql_Dll.SQL.Add('SELECT * FROM MNSA_USERLIST');
sql_Dll.open;
ShowModal;
if ModalResult = mrOK then
Begin
EnPassWord :=sql_Dll.FieldByName('PASSWORD').AsString;
EnPassWord :=MNSA_Decrypt(EnPassWord); //解密
if UpperCase(e_PassWord.Text) = UpperCase(EnPassWord) then //登录成功
Begin
StrPCopy(aUserName,sql_Dll.FieldByName('USER_ID').AsString);
StrPCopy(aUserID,sql_Dll.FieldByName('USER_NAME').AsString);
aJuri :=sql_Dll.FieldByName('POPEDOM').AsInteger;
if sql_Dll.FieldByName('FIRSTLOGIN').AsInteger = 0 then
ShowMessage('你是第一次登录,请修改你的密码');
Result :=True;
end;
end;
finally
sql_Dll.Close;
sql_Dll.Free;
ds_UserList.Free;
DataBase.Connected :=False;
DataBase.Free;
StrDispose(IPAddr);
Free;
end;
end;
end;
end.
library user;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
un_changepass in 'un_changepass.pas' {frm_ChangePass},
un_command in 'un_command.pas',
un_userlogin in 'un_userlogin.pas' {frm_UserLogin},
un_about in 'un_about.pas' {frm_About},
un_Crypt32 in '..\公用声明\un_Crypt32.pas',
un_dbtools in '..\公用声明\un_dbtools.pas';
{$R *.RES}
exports
MSNA_CertifyIsRunToCurrentComputer name 'MSNA_CertifyIsRunToCurrentComputer', //是否可以运行
MSNA_CertifyUserLogin name 'MSNA_CertifyUserLogin', //验证登录
MSNA_ChangePassWord name 'MSNA_ChangePassWord', //改变密码
MNSA_ShowApplicationAboutMessage name 'MNSA_ShowApplicationAboutMessage', //显示关于窗口
MSNA_GetCurrentComputerIPAddress name 'MSNA_GetCurrentComputerIPAddress'; //取得当前计算机IP地址
begin
end.
{=======================================================================
// Application:
// Unit Function:
// 用户登录验证
// Author:alin
// DateTime:2001.09.27
// Change:
// DateTime:
========================================================================}
unit un_userlogin;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, jpeg,dbtables, Db, Grids, DBGrids, DBCtrls;
type
Tfrm_UserLogin = class(TForm)
Image1: TImage;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
e_PassWord: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
dblcb_User: TDBLookupComboBox;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_UserLogin: Tfrm_UserLogin;
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
implementation
uses un_command, un_Crypt32, un_dbtools;
{$R *.DFM}
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
var
IPAddr:PChar;
EnPassWord:String;
DataBase:TDataBase;
sql_Dll:TQuery;
ds_UserList:TDataSource;
Begin
Result :=False;
Application.Handle :=aHandle;
IPAddr :=StrAlloc(30);
MSNA_GetCurrentComputerIPAddress(IPAddr);
frm_UserLogin:=Tfrm_UserLogin.Create(Application);
DataBase:=TDataBase.Create(frm_UserLogin);
sql_Dll:=TQuery.Create(frm_UserLogin);
ds_UserList:=TDataSource.Create(frm_UserLogin);
ds_UserList.DataSet :=sql_Dll;
DataBase.DatabaseName :='DLL_DATA';
DataBase.LoginPrompt :=False;
sql_Dll.DatabaseName :=Database.DatabaseName;
with frm_UserLogin do
Begin
Try
dblcb_User.ListSource :=ds_UserList;
ConnectDataBase(DataBase);
sql_Dll.Close;
sql_Dll.SQL.Clear;
sql_Dll.SQL.Add('SELECT * FROM MNSA_USERLIST');
sql_Dll.open;
ShowModal;
if ModalResult = mrOK then
Begin
EnPassWord :=sql_Dll.FieldByName('PASSWORD').AsString;
EnPassWord :=MNSA_Decrypt(EnPassWord); //解密
if UpperCase(e_PassWord.Text) = UpperCase(EnPassWord) then //登录成功
Begin
StrPCopy(aUserName,sql_Dll.FieldByName('USER_ID').AsString);
StrPCopy(aUserID,sql_Dll.FieldByName('USER_NAME').AsString);
aJuri :=sql_Dll.FieldByName('POPEDOM').AsInteger;
if sql_Dll.FieldByName('FIRSTLOGIN').AsInteger = 0 then
ShowMessage('你是第一次登录,请修改你的密码');
Result :=True;
end;
end;
finally
sql_Dll.Close;
sql_Dll.Free;
ds_UserList.Free;
DataBase.Connected :=False;
DataBase.Free;
StrDispose(IPAddr);
Free;
end;
end;
end;
end.
#19
这几天我反复试,经常出错,系统都死掉
#20
请多多关注!
#21
在www.borland.com.tw上
李维老师有篇文章
不知各位看过没有
是用包文件来解决
李维老师有篇文章
不知各位看过没有
是用包文件来解决
#22
关注 upup
#23
我就不信没人知道
#24
u~~~~p
#25
关注中~~~
#26
我用的ADO,
OK,通过!
相信也没有问题:
function ShowMyForm(MyDataBase: TDataBase):integer;Stdcall;
begin
MyForm := TMyFOrm.Create;
with MyForm do
begin
MyQuery.DataBase := MyDataBase;
Result := ShowModal;
Free;
end;
end;
OK,通过!
相信也没有问题:
function ShowMyForm(MyDataBase: TDataBase):integer;Stdcall;
begin
MyForm := TMyFOrm.Create;
with MyForm do
begin
MyQuery.DataBase := MyDataBase;
Result := ShowModal;
Free;
end;
end;
#27
提一点建议
是不是要在dll里面重新打开一个会话Session。而不是传一个database进去
是不是要在dll里面重新打开一个会话Session。而不是传一个database进去
#28
用session来传递,在DLL中export出一个函数,函数的参数是TSession
如:在dll中的函数:
funtion Sharedate(s : TSession) : boolean;
begin
Session := s;
...
end;
即把Session做为参数传到DLL中替换DLL中的Session就行了.
应用程序中调用:
Sharedata(session);
如:在dll中的函数:
funtion Sharedate(s : TSession) : boolean;
begin
Session := s;
...
end;
即把Session做为参数传到DLL中替换DLL中的Session就行了.
应用程序中调用:
Sharedata(session);
#29
补充:
在DLL中Form 上的Table.DatabaseName设置为应用程序中DataBase1.Databasename即可
在DLL中Form 上的Table.DatabaseName设置为应用程序中DataBase1.Databasename即可
#30
我先试试看再说
#31
也试下先。
#32
DLL问题真多,用的不熟真不爽,调试程序动不动就死机
#33
u p
#34
到现在我还是没能解决
#35
不用dll,用bpl就完全可以解决问题。
看一下www.borland.com.tw上李维的文章。
《如 何 使 用 Delphi 开 发 大 型 主 从 架 构 系 统 - Package 的 秘 密 和 威 力》
看一下www.borland.com.tw上李维的文章。
《如 何 使 用 Delphi 开 发 大 型 主 从 架 构 系 统 - Package 的 秘 密 和 威 力》
#36
目前我还不想用BPL,我还是一步一步来,不要走路还没学会,就学跑
#37
经常报错用如下办法
在DLL里,声明一个
var
dllapplication:tapplication;
再加入
initialization
DLLApplication:=Application;
finalization
Application:=DLLApplication;
在DLL里,声明一个
var
dllapplication:tapplication;
再加入
initialization
DLLApplication:=Application;
finalization
Application:=DLLApplication;
#38
:)
这个问题我来帮你吧
一个exe文件,一个dll文件
在dll 的窗体里不要放database,而是在public里声明一个database;
在exe文件里放好database,设置好
以下是源代码
dll文件
导出函数为showform;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
private
{ Private declarations }
public
database1:tdatabase;
{ Public declarations }
end;
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
var
Form1: TForm1;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
begin
application:=applicationname;
application.CreateForm(tform1,form1);
form1.Database1:=databasename;
form1.Table1.DatabaseName:=form1.database1.DatabaseName;
form1.table1.Open;
form1.ShowModal;
form1.Free;
end;
initialization
dllapplication:=application;
finalization
dllapplication:=application;
end.
exe文件
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;
type
TForm2 = class(TForm)
Database1: TDatabase;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure showform(applicationname:tapplication;database:tdatabase);stdcall;external 'dllfile.dll' name 'showform';
var
Form2: TForm2;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
showform(application,database1);
end;
end.
这个问题我来帮你吧
一个exe文件,一个dll文件
在dll 的窗体里不要放database,而是在public里声明一个database;
在exe文件里放好database,设置好
以下是源代码
dll文件
导出函数为showform;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
private
{ Private declarations }
public
database1:tdatabase;
{ Public declarations }
end;
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
var
Form1: TForm1;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
begin
application:=applicationname;
application.CreateForm(tform1,form1);
form1.Database1:=databasename;
form1.Table1.DatabaseName:=form1.database1.DatabaseName;
form1.table1.Open;
form1.ShowModal;
form1.Free;
end;
initialization
dllapplication:=application;
finalization
dllapplication:=application;
end.
exe文件
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;
type
TForm2 = class(TForm)
Database1: TDatabase;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure showform(applicationname:tapplication;database:tdatabase);stdcall;external 'dllfile.dll' name 'showform';
var
Form2: TForm2;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
showform(application,database1);
end;
end.
#1
可以,传一个TTable或者TQuery类型的参数不OK了?
或者传一个TDatabase参数,在dll中做好连接等设置。
或者传一个TDatabase参数,在dll中做好连接等设置。
#2
在调用dll时将应用程序的参数赋值给dll。
#3
有例子吗,我也想知道
#4
我今天中午还在思这个问题,能不能在一个DLL中使不同程序共享一个对共享一个对象的变量和方法。谁有这方面的经验,来交流交流
#5
我曾经试过,会报错
#6
我等米下锅
#7
用文件印射好你很难,用DDE又好像不可能。
谁能实现请告知,好想知道
谁能实现请告知,好想知道
#8
因为连接的是SQL的数据库,所以有数据库登录对话框
我在DLL中的那些过程是把Application作为参数传进去的
procedure showform1(MainApp:TApplication);stdcall;export;
var
form1: form1;
begin
if not Assigned(DllApp) then
begin
DllApp := Application;
Application := MainApp;
end;
try
form1:= Tform1.Create(Application);
form1.Show();
except
form1.Free();
end;
end;
我在DLL中的那些过程是把Application作为参数传进去的
procedure showform1(MainApp:TApplication);stdcall;export;
var
form1: form1;
begin
if not Assigned(DllApp) then
begin
DllApp := Application;
Application := MainApp;
end;
try
form1:= Tform1.Create(Application);
form1.Show();
except
form1.Free();
end;
end;
#9
传参数时在我退出应用时会死掉
#10
我在线等候回答
#11
我等,我等......
#12
我已经献出我能给的最高分了
#13
帮你up
#14
I WAIT YOUR ANSWER
#15
答案在何方?
#16
我曾经做过,.dll包含一个login窗体(用ado连接),调用都没问题,只是关闭应用程序时,提示'kernel32.dll'出错,不知为什么
#17
怎么回答这么少呢?
#18
我也想知道不用重新联接TDATABASE就能完成,以下是我在工程中应用的DLL例子部份,但每个FROM都需重定义TDATABASE
library user;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
un_changepass in 'un_changepass.pas' {frm_ChangePass},
un_command in 'un_command.pas',
un_userlogin in 'un_userlogin.pas' {frm_UserLogin},
un_about in 'un_about.pas' {frm_About},
un_Crypt32 in '..\公用声明\un_Crypt32.pas',
un_dbtools in '..\公用声明\un_dbtools.pas';
{$R *.RES}
exports
MSNA_CertifyIsRunToCurrentComputer name 'MSNA_CertifyIsRunToCurrentComputer', //是否可以运行
MSNA_CertifyUserLogin name 'MSNA_CertifyUserLogin', //验证登录
MSNA_ChangePassWord name 'MSNA_ChangePassWord', //改变密码
MNSA_ShowApplicationAboutMessage name 'MNSA_ShowApplicationAboutMessage', //显示关于窗口
MSNA_GetCurrentComputerIPAddress name 'MSNA_GetCurrentComputerIPAddress'; //取得当前计算机IP地址
begin
end.
{=======================================================================
// Application:
// Unit Function:
// 用户登录验证
// Author:alin
// DateTime:2001.09.27
// Change:
// DateTime:
========================================================================}
unit un_userlogin;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, jpeg,dbtables, Db, Grids, DBGrids, DBCtrls;
type
Tfrm_UserLogin = class(TForm)
Image1: TImage;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
e_PassWord: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
dblcb_User: TDBLookupComboBox;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_UserLogin: Tfrm_UserLogin;
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
implementation
uses un_command, un_Crypt32, un_dbtools;
{$R *.DFM}
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
var
IPAddr:PChar;
EnPassWord:String;
DataBase:TDataBase;
sql_Dll:TQuery;
ds_UserList:TDataSource;
Begin
Result :=False;
Application.Handle :=aHandle;
IPAddr :=StrAlloc(30);
MSNA_GetCurrentComputerIPAddress(IPAddr);
frm_UserLogin:=Tfrm_UserLogin.Create(Application);
DataBase:=TDataBase.Create(frm_UserLogin);
sql_Dll:=TQuery.Create(frm_UserLogin);
ds_UserList:=TDataSource.Create(frm_UserLogin);
ds_UserList.DataSet :=sql_Dll;
DataBase.DatabaseName :='DLL_DATA';
DataBase.LoginPrompt :=False;
sql_Dll.DatabaseName :=Database.DatabaseName;
with frm_UserLogin do
Begin
Try
dblcb_User.ListSource :=ds_UserList;
ConnectDataBase(DataBase);
sql_Dll.Close;
sql_Dll.SQL.Clear;
sql_Dll.SQL.Add('SELECT * FROM MNSA_USERLIST');
sql_Dll.open;
ShowModal;
if ModalResult = mrOK then
Begin
EnPassWord :=sql_Dll.FieldByName('PASSWORD').AsString;
EnPassWord :=MNSA_Decrypt(EnPassWord); //解密
if UpperCase(e_PassWord.Text) = UpperCase(EnPassWord) then //登录成功
Begin
StrPCopy(aUserName,sql_Dll.FieldByName('USER_ID').AsString);
StrPCopy(aUserID,sql_Dll.FieldByName('USER_NAME').AsString);
aJuri :=sql_Dll.FieldByName('POPEDOM').AsInteger;
if sql_Dll.FieldByName('FIRSTLOGIN').AsInteger = 0 then
ShowMessage('你是第一次登录,请修改你的密码');
Result :=True;
end;
end;
finally
sql_Dll.Close;
sql_Dll.Free;
ds_UserList.Free;
DataBase.Connected :=False;
DataBase.Free;
StrDispose(IPAddr);
Free;
end;
end;
end;
end.
library user;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
un_changepass in 'un_changepass.pas' {frm_ChangePass},
un_command in 'un_command.pas',
un_userlogin in 'un_userlogin.pas' {frm_UserLogin},
un_about in 'un_about.pas' {frm_About},
un_Crypt32 in '..\公用声明\un_Crypt32.pas',
un_dbtools in '..\公用声明\un_dbtools.pas';
{$R *.RES}
exports
MSNA_CertifyIsRunToCurrentComputer name 'MSNA_CertifyIsRunToCurrentComputer', //是否可以运行
MSNA_CertifyUserLogin name 'MSNA_CertifyUserLogin', //验证登录
MSNA_ChangePassWord name 'MSNA_ChangePassWord', //改变密码
MNSA_ShowApplicationAboutMessage name 'MNSA_ShowApplicationAboutMessage', //显示关于窗口
MSNA_GetCurrentComputerIPAddress name 'MSNA_GetCurrentComputerIPAddress'; //取得当前计算机IP地址
begin
end.
{=======================================================================
// Application:
// Unit Function:
// 用户登录验证
// Author:alin
// DateTime:2001.09.27
// Change:
// DateTime:
========================================================================}
unit un_userlogin;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, jpeg,dbtables, Db, Grids, DBGrids, DBCtrls;
type
Tfrm_UserLogin = class(TForm)
Image1: TImage;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
e_PassWord: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
dblcb_User: TDBLookupComboBox;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_UserLogin: Tfrm_UserLogin;
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
implementation
uses un_command, un_Crypt32, un_dbtools;
{$R *.DFM}
function MSNA_CertifyUserLogin(const aHandle:Integer;
const aAppID:PChar;Var aUserID,aUserName:PChar;
Var aJuri:Integer;Var CurrentUse:Boolean):Boolean;
var
IPAddr:PChar;
EnPassWord:String;
DataBase:TDataBase;
sql_Dll:TQuery;
ds_UserList:TDataSource;
Begin
Result :=False;
Application.Handle :=aHandle;
IPAddr :=StrAlloc(30);
MSNA_GetCurrentComputerIPAddress(IPAddr);
frm_UserLogin:=Tfrm_UserLogin.Create(Application);
DataBase:=TDataBase.Create(frm_UserLogin);
sql_Dll:=TQuery.Create(frm_UserLogin);
ds_UserList:=TDataSource.Create(frm_UserLogin);
ds_UserList.DataSet :=sql_Dll;
DataBase.DatabaseName :='DLL_DATA';
DataBase.LoginPrompt :=False;
sql_Dll.DatabaseName :=Database.DatabaseName;
with frm_UserLogin do
Begin
Try
dblcb_User.ListSource :=ds_UserList;
ConnectDataBase(DataBase);
sql_Dll.Close;
sql_Dll.SQL.Clear;
sql_Dll.SQL.Add('SELECT * FROM MNSA_USERLIST');
sql_Dll.open;
ShowModal;
if ModalResult = mrOK then
Begin
EnPassWord :=sql_Dll.FieldByName('PASSWORD').AsString;
EnPassWord :=MNSA_Decrypt(EnPassWord); //解密
if UpperCase(e_PassWord.Text) = UpperCase(EnPassWord) then //登录成功
Begin
StrPCopy(aUserName,sql_Dll.FieldByName('USER_ID').AsString);
StrPCopy(aUserID,sql_Dll.FieldByName('USER_NAME').AsString);
aJuri :=sql_Dll.FieldByName('POPEDOM').AsInteger;
if sql_Dll.FieldByName('FIRSTLOGIN').AsInteger = 0 then
ShowMessage('你是第一次登录,请修改你的密码');
Result :=True;
end;
end;
finally
sql_Dll.Close;
sql_Dll.Free;
ds_UserList.Free;
DataBase.Connected :=False;
DataBase.Free;
StrDispose(IPAddr);
Free;
end;
end;
end;
end.
#19
这几天我反复试,经常出错,系统都死掉
#20
请多多关注!
#21
在www.borland.com.tw上
李维老师有篇文章
不知各位看过没有
是用包文件来解决
李维老师有篇文章
不知各位看过没有
是用包文件来解决
#22
关注 upup
#23
我就不信没人知道
#24
u~~~~p
#25
关注中~~~
#26
我用的ADO,
OK,通过!
相信也没有问题:
function ShowMyForm(MyDataBase: TDataBase):integer;Stdcall;
begin
MyForm := TMyFOrm.Create;
with MyForm do
begin
MyQuery.DataBase := MyDataBase;
Result := ShowModal;
Free;
end;
end;
OK,通过!
相信也没有问题:
function ShowMyForm(MyDataBase: TDataBase):integer;Stdcall;
begin
MyForm := TMyFOrm.Create;
with MyForm do
begin
MyQuery.DataBase := MyDataBase;
Result := ShowModal;
Free;
end;
end;
#27
提一点建议
是不是要在dll里面重新打开一个会话Session。而不是传一个database进去
是不是要在dll里面重新打开一个会话Session。而不是传一个database进去
#28
用session来传递,在DLL中export出一个函数,函数的参数是TSession
如:在dll中的函数:
funtion Sharedate(s : TSession) : boolean;
begin
Session := s;
...
end;
即把Session做为参数传到DLL中替换DLL中的Session就行了.
应用程序中调用:
Sharedata(session);
如:在dll中的函数:
funtion Sharedate(s : TSession) : boolean;
begin
Session := s;
...
end;
即把Session做为参数传到DLL中替换DLL中的Session就行了.
应用程序中调用:
Sharedata(session);
#29
补充:
在DLL中Form 上的Table.DatabaseName设置为应用程序中DataBase1.Databasename即可
在DLL中Form 上的Table.DatabaseName设置为应用程序中DataBase1.Databasename即可
#30
我先试试看再说
#31
也试下先。
#32
DLL问题真多,用的不熟真不爽,调试程序动不动就死机
#33
u p
#34
到现在我还是没能解决
#35
不用dll,用bpl就完全可以解决问题。
看一下www.borland.com.tw上李维的文章。
《如 何 使 用 Delphi 开 发 大 型 主 从 架 构 系 统 - Package 的 秘 密 和 威 力》
看一下www.borland.com.tw上李维的文章。
《如 何 使 用 Delphi 开 发 大 型 主 从 架 构 系 统 - Package 的 秘 密 和 威 力》
#36
目前我还不想用BPL,我还是一步一步来,不要走路还没学会,就学跑
#37
经常报错用如下办法
在DLL里,声明一个
var
dllapplication:tapplication;
再加入
initialization
DLLApplication:=Application;
finalization
Application:=DLLApplication;
在DLL里,声明一个
var
dllapplication:tapplication;
再加入
initialization
DLLApplication:=Application;
finalization
Application:=DLLApplication;
#38
:)
这个问题我来帮你吧
一个exe文件,一个dll文件
在dll 的窗体里不要放database,而是在public里声明一个database;
在exe文件里放好database,设置好
以下是源代码
dll文件
导出函数为showform;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
private
{ Private declarations }
public
database1:tdatabase;
{ Public declarations }
end;
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
var
Form1: TForm1;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
begin
application:=applicationname;
application.CreateForm(tform1,form1);
form1.Database1:=databasename;
form1.Table1.DatabaseName:=form1.database1.DatabaseName;
form1.table1.Open;
form1.ShowModal;
form1.Free;
end;
initialization
dllapplication:=application;
finalization
dllapplication:=application;
end.
exe文件
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;
type
TForm2 = class(TForm)
Database1: TDatabase;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure showform(applicationname:tapplication;database:tdatabase);stdcall;external 'dllfile.dll' name 'showform';
var
Form2: TForm2;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
showform(application,database1);
end;
end.
这个问题我来帮你吧
一个exe文件,一个dll文件
在dll 的窗体里不要放database,而是在public里声明一个database;
在exe文件里放好database,设置好
以下是源代码
dll文件
导出函数为showform;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
private
{ Private declarations }
public
database1:tdatabase;
{ Public declarations }
end;
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
var
Form1: TForm1;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure showform(applicationname:tapplication;databasename:tdatabase);stdcall;
begin
application:=applicationname;
application.CreateForm(tform1,form1);
form1.Database1:=databasename;
form1.Table1.DatabaseName:=form1.database1.DatabaseName;
form1.table1.Open;
form1.ShowModal;
form1.Free;
end;
initialization
dllapplication:=application;
finalization
dllapplication:=application;
end.
exe文件
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;
type
TForm2 = class(TForm)
Database1: TDatabase;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure showform(applicationname:tapplication;database:tdatabase);stdcall;external 'dllfile.dll' name 'showform';
var
Form2: TForm2;
dllapplication:tapplication;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
showform(application,database1);
end;
end.