G
gmsft
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的程序执行正常:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function UserLogin(UserName, UserPSWD: string): boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.UserLogin(UserName, UserPSWD: string): boolean;
var
DBQry: TADOQuery;
begin
DBQry := TADOQuery.Create(nil);
DBQry.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=D:/Projects/IDEMO/Database.mdb;'+
'Persist Security Info=False';
DBQry.Close;
DBQry.SQL.Clear;
DBQry.SQL.Add('SELECT Name FROM employees');
DBQry.SQL.Add(' WHERE ID = :ID and PSWD = SWD');
DBQry.Parameters.ParamByName('ID').Value := UserName;
DBQry.Parameters.ParamByName('PSWD').Value := UserPSWD;
DBQry.Open;
result := not (DBQry.RecordCount = 0);
DBQry.Close;
DBQry.Free;
DBQry := nil;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if UserLogin(Edit1.Text, Edit2.Text) then
ShowMessage('登录成功!')
else
ShowMessage('登录失败!');
end;
end.
写进 DLL 后,不能执行, 提示:
"exception EOleSySError in module Project1.dll at 00026FE9."
library Project1;
{ 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
ShareMem,
SysUtils,
ADODB,
Classes;
{$R *.res}
function UserLogin(UserName, UserPSWD: string): boolean;
var
DBQry: TADOQuery;
begin
DBQry := TADOQuery.Create(nil);
DBQry.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=D:/Projects/IDEMO/Database.mdb;'+
'Persist Security Info=False';
DBQry.Close;
DBQry.SQL.Clear;
DBQry.SQL.Add('SELECT Name FROM employees');
DBQry.SQL.Add(' WHERE ID = :ID and PSWD = SWD');
DBQry.Parameters.ParamByName('ID').Value := UserName;
DBQry.Parameters.ParamByName('PSWD').Value := UserPSWD;
DBQry.Open;
result := not (DBQry.RecordCount = 0);
DBQry.Close;
DBQry.Free;
DBQry := nil;
end;
exports
UserLogin;
begin
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function UserLogin(UserName, UserPSWD: string): boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.UserLogin(UserName, UserPSWD: string): boolean;
var
DBQry: TADOQuery;
begin
DBQry := TADOQuery.Create(nil);
DBQry.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=D:/Projects/IDEMO/Database.mdb;'+
'Persist Security Info=False';
DBQry.Close;
DBQry.SQL.Clear;
DBQry.SQL.Add('SELECT Name FROM employees');
DBQry.SQL.Add(' WHERE ID = :ID and PSWD = SWD');
DBQry.Parameters.ParamByName('ID').Value := UserName;
DBQry.Parameters.ParamByName('PSWD').Value := UserPSWD;
DBQry.Open;
result := not (DBQry.RecordCount = 0);
DBQry.Close;
DBQry.Free;
DBQry := nil;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if UserLogin(Edit1.Text, Edit2.Text) then
ShowMessage('登录成功!')
else
ShowMessage('登录失败!');
end;
end.
写进 DLL 后,不能执行, 提示:
"exception EOleSySError in module Project1.dll at 00026FE9."
library Project1;
{ 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
ShareMem,
SysUtils,
ADODB,
Classes;
{$R *.res}
function UserLogin(UserName, UserPSWD: string): boolean;
var
DBQry: TADOQuery;
begin
DBQry := TADOQuery.Create(nil);
DBQry.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=D:/Projects/IDEMO/Database.mdb;'+
'Persist Security Info=False';
DBQry.Close;
DBQry.SQL.Clear;
DBQry.SQL.Add('SELECT Name FROM employees');
DBQry.SQL.Add(' WHERE ID = :ID and PSWD = SWD');
DBQry.Parameters.ParamByName('ID').Value := UserName;
DBQry.Parameters.ParamByName('PSWD').Value := UserPSWD;
DBQry.Open;
result := not (DBQry.RecordCount = 0);
DBQry.Close;
DBQry.Free;
DBQry := nil;
end;
exports
UserLogin;
begin
end.