//代码如下,在线等,我的msn 是[email protected] 请各位指教library SpIvr;
uses
SysUtils,
Classes,
ExportUnit in 'ExportUnit.pas',
LoginF in 'LoginF.pas' {dmdLoginF: TDataModule};{$R *.res}begin
end.////////////////////////////////////unit ExportUnit;interface
// 初始化动态链接库
function InitialDll: Integer; stdcall;
//登陆验证
function checklogin(sender:integer;phoneno,passwordno:pchar):pchar;stdcall;
exports
InitialDll,
checklogin;
implementation
uses SysUtils, LoginF;// 初始化动态链接库
function InitialDll: Integer;
begin
result := 1;
end;function checklogin(sender:integer;phoneno,passwordno:pchar):pchar;
var
strResult: String;
phno,pws:string;
begin
phno:=phoneno;
pws:=passwordno;
strResult := dmdLoginF.checkpw(phno,pws);
if strresult='1'then
begin
result:='1';
end else
begin
result:='0';
end;
end;end.//////////////////////////////////////////unit LoginF;interfaceuses
SysUtils, Classes, DB,ADODB,connectDB,ActiveX;type
TdmdLoginF = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function checkpw(phno,pws:string): String;
end;var
dmdLoginF: TdmdLoginF;implementation{$R *.dfm}function TdmdLoginF.checkpw(phno,pws:string): String;
var sqlstr:string;
query1:Tadoquery;
cnn:tadoconnection;
begin
CoInitialize( nil );
try
query1:=Tadoquery.Create(nil);
cnn:=tadoconnection.Create(nil);
cnn.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=HAPOOK';
cnn.LoginPrompt :=false;
cnn.Open;
query1.Connection :=cnn;
query1.Close;
sqlstr:='select * from weatherforecast';
query1.SQL.Clear;
query1.sql.Append(sqlstr);
query1.open; //????????????????????????好像是这里过不了,但不知道为什么
if not query1.Eof then
result := '1'
else
result:='0';
except
end;end;procedure TdmdLoginF.DataModuleCreate(Sender: TObject);
begin
//Connection1.LoginPrompt :=false;
// OpenDatabase;
end;procedure TdmdLoginF.DataModuleDestroy(Sender: TObject);
begin
// connection1.Close;
CoUnInitialize;//必须使用end;end.
uses
SysUtils,
Classes,
ExportUnit in 'ExportUnit.pas',
LoginF in 'LoginF.pas' {dmdLoginF: TDataModule};{$R *.res}begin
end.////////////////////////////////////unit ExportUnit;interface
// 初始化动态链接库
function InitialDll: Integer; stdcall;
//登陆验证
function checklogin(sender:integer;phoneno,passwordno:pchar):pchar;stdcall;
exports
InitialDll,
checklogin;
implementation
uses SysUtils, LoginF;// 初始化动态链接库
function InitialDll: Integer;
begin
result := 1;
end;function checklogin(sender:integer;phoneno,passwordno:pchar):pchar;
var
strResult: String;
phno,pws:string;
begin
phno:=phoneno;
pws:=passwordno;
strResult := dmdLoginF.checkpw(phno,pws);
if strresult='1'then
begin
result:='1';
end else
begin
result:='0';
end;
end;end.//////////////////////////////////////////unit LoginF;interfaceuses
SysUtils, Classes, DB,ADODB,connectDB,ActiveX;type
TdmdLoginF = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function checkpw(phno,pws:string): String;
end;var
dmdLoginF: TdmdLoginF;implementation{$R *.dfm}function TdmdLoginF.checkpw(phno,pws:string): String;
var sqlstr:string;
query1:Tadoquery;
cnn:tadoconnection;
begin
CoInitialize( nil );
try
query1:=Tadoquery.Create(nil);
cnn:=tadoconnection.Create(nil);
cnn.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=HAPOOK';
cnn.LoginPrompt :=false;
cnn.Open;
query1.Connection :=cnn;
query1.Close;
sqlstr:='select * from weatherforecast';
query1.SQL.Clear;
query1.sql.Append(sqlstr);
query1.open; //????????????????????????好像是这里过不了,但不知道为什么
if not query1.Eof then
result := '1'
else
result:='0';
except
end;end;procedure TdmdLoginF.DataModuleCreate(Sender: TObject);
begin
//Connection1.LoginPrompt :=false;
// OpenDatabase;
end;procedure TdmdLoginF.DataModuleDestroy(Sender: TObject);
begin
// connection1.Close;
CoUnInitialize;//必须使用end;end.
应该要就ado进行初始化
试试看!
怎样初始话?我用的是:CoInitialize( nil );CoUnInitialize;
谢谢您的帮忙!我找到原因了,是我的数据库名称写错了,应该是hansp3的,被写成了master.
cnn.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master(就是这里);Data Source=HAPOOK';
我的msn 是[email protected]