幸
幸福鸟
Unregistered / Unconfirmed
GUEST, unregistred user!
怎样做个DLL的登陆窗体,输入用户名和密码后由DLL连接数据库并验证!!
我现在做了个dll窗体,但在上面放adoconnection控件和adoquery控件后运行时
出现错误,我的adoconnection和adoquery都已经配置好,
是布是dll不支持这样连接啊,该怎样办啊!!!!
dll是這樣的:
library ProjectDll;
uses
SysUtils,
Classes,
Forms,
Windows,
ufrmDll in 'ufrmDll.pas' {frmDll};
{$R *.res}
var
DLLApp: TApplication;
DLLScr: TScreen;
function TestDll(App: TApplication;
Scr: TScreen):TForm;
begin
Application := App;
Screen := Scr;
if frmDll=nil then
begin
Application.CreateForm(TfrmDll, frmDll);
frmDll.Show;
result:=frmDll;
end
else
result:=nil;
end;
procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
TestDll;
begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;
end.
dll窗體是這樣的,上面有adoconnection控件和adotable控件,都已經連接好
unit ufrmDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, Grids, DBGrids, ADODB;
type
TfrmDll = class(TForm)
Label1: TLabel;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
public
end;
var
frmDll: TfrmDll;
implementation
{$R *.dfm}
procedure TfrmDll.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
frmDll:=nil;
action:=cafree;
end;
在測試窗體中的button事件是這樣的
procedure TfrmDllTest.Button1Click(Sender: TObject);
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;
begin
DLLHandle := LoadLibrary('ProjectDll.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'TestDll');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
end;
運行後彈出錯誤
project projectDllTest.exe raised exception class EOleSysError With message 'CoInitialize 尚未被呼叫。',Process stopped.Use Step or Run to continue.
但我把adoconnection和adoquery 控件去掉就沒問題,不知錯那裡了啊?幫幫忙
我现在做了个dll窗体,但在上面放adoconnection控件和adoquery控件后运行时
出现错误,我的adoconnection和adoquery都已经配置好,
是布是dll不支持这样连接啊,该怎样办啊!!!!
dll是這樣的:
library ProjectDll;
uses
SysUtils,
Classes,
Forms,
Windows,
ufrmDll in 'ufrmDll.pas' {frmDll};
{$R *.res}
var
DLLApp: TApplication;
DLLScr: TScreen;
function TestDll(App: TApplication;
Scr: TScreen):TForm;
begin
Application := App;
Screen := Scr;
if frmDll=nil then
begin
Application.CreateForm(TfrmDll, frmDll);
frmDll.Show;
result:=frmDll;
end
else
result:=nil;
end;
procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
TestDll;
begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;
end.
dll窗體是這樣的,上面有adoconnection控件和adotable控件,都已經連接好
unit ufrmDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, Grids, DBGrids, ADODB;
type
TfrmDll = class(TForm)
Label1: TLabel;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
public
end;
var
frmDll: TfrmDll;
implementation
{$R *.dfm}
procedure TfrmDll.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
frmDll:=nil;
action:=cafree;
end;
在測試窗體中的button事件是這樣的
procedure TfrmDllTest.Button1Click(Sender: TObject);
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;
begin
DLLHandle := LoadLibrary('ProjectDll.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'TestDll');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
end;
運行後彈出錯誤
project projectDllTest.exe raised exception class EOleSysError With message 'CoInitialize 尚未被呼叫。',Process stopped.Use Step or Run to continue.
但我把adoconnection和adoquery 控件去掉就沒問題,不知錯那裡了啊?幫幫忙