delphi dll封闭窗体登录封装到DLL的例子.doc

上传人:ni****g 文档编号:547739972 上传时间:2023-02-11 格式:DOC 页数:6 大小:71.01KB
返回 下载 相关 举报
delphi dll封闭窗体登录封装到DLL的例子.doc_第1页
第1页 / 共6页
delphi dll封闭窗体登录封装到DLL的例子.doc_第2页
第2页 / 共6页
delphi dll封闭窗体登录封装到DLL的例子.doc_第3页
第3页 / 共6页
delphi dll封闭窗体登录封装到DLL的例子.doc_第4页
第4页 / 共6页
delphi dll封闭窗体登录封装到DLL的例子.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《delphi dll封闭窗体登录封装到DLL的例子.doc》由会员分享,可在线阅读,更多相关《delphi dll封闭窗体登录封装到DLL的例子.doc(6页珍藏版)》请在金锄头文库上搜索。

1、Delphi登录封装到DLL这是一个把登录封装到DLL的例子,当前程序还包括自动建立数据库,给数据库加密码。UNIT frm_pws;INTERFACEUSES Windows, SysUtils, Controls, Forms, DB, ADODB, Classes, StdCtrls;TYPE Tfrmpws = CLASS(TForm) Label1:TLabel; Edit1:TEdit; Label2:TLabel; Edit2:TEdit; Button1:TButton; Button2:TButton; ADOQuery1:TADOQuery; PROCEDURE Butto

2、n1Click(Sender:TObject); PROCEDURE Button2Click(Sender:TObject); PRIVATE Private declarations PUBLIC Public declarations END;VAR frmpws :Tfrmpws; logincount :integer;IMPLEMENTATION$R *.dfmPROCEDURE Tfrmpws.Button1Click(Sender:TObject);VAR sql :STRING;BEGIN sql := select * from pws + where user= + ed

3、it1.Text + + and pwd= + edit2.Text + ; ADOQuery1.SQL.Text := sql; ADOQuery1.Active := true; inc(logincount); IF (logincount 4) THEN self.ModalResult := mrcancel ELSE BEGIN IF NOT ADOQuery1.IsEmpty THEN BEGIN ModalResult := mrok; ADOQuery1.Active := false; END ELSE BEGIN edit1.Text := ; edit2.text :=

4、 ; END; END;END;PROCEDURE Tfrmpws.Button2Click(Sender:TObject);BEGIN ModalResult := mrcancel;END;END.LIBRARY pws; Important note about DLL memory management: ShareMem must be the first unit in your librarys USES clause AND your projects (select Project-View Source) USES clause if your DLL exports an

5、y 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 D

6、LL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. USES SysUtils, Classes, Controls, frm_pws IN frm_pws.pas frmpws;VAR myCnn :STRING; $R *.resFUNCTION checkpwd:boolean; STDCALL;VAR frmpws :tfrmpws;BEGIN IF mycnn = THEN BEGIN result := false; exit; END ELS

7、E BEGIN frmpws := tfrmpws.Create(NIL); TRY frmpws.ADOQuery1.ConnectionString := mycnn; result := frmpws.ShowModal = mrok; FINALLY frmpws.free; END; END;END;PROCEDURE setCNN(cnn:STRING); STDCALL;BEGIN myCnn := cnn;END;EXPORTS setCNN, checkpwd;BEGINEND.program Project1;uses Forms, Unit1 in Unit1.pas F

8、orm1;$R *.resbegin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run;end.UNIT Unit1;INTERFACEUSES Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComObj, DB, ADODB;TYPE TForm1 = CLASS(TForm) Button1:TButton; Button2:TButton;

9、ADOQuery1:TADOQuery; PROCEDURE Button1Click(Sender:TObject); PROCEDURE Button2Click(Sender:TObject); PRIVATE Private declarations PUBLIC Public declarations END;CONST cnnstr = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=PWS.mdb;Jet OLEDB:Database Password=123456;VAR Form1 :TForm1;PROCEDURE setCNN(c

10、nn:STRING); stdcall; external pws.dll;FUNCTION checkpwd:boolean; stdcall; external pws.dll;IMPLEMENTATION$R *.dfmPROCEDURE TForm1.Button1Click(Sender:TObject);VAR CreateAccess :OleVariant;BEGIN IF fileexists(PWS.mdb) THEN deletefile(PWS.mdb); TRY CreateAccess := CreateOleObject(ADOX.Catalog); Create

11、Access.Create(cnnstr); EXCEPT / END; WITH ADOQuery1 DO BEGIN ConnectionString := cnnstr; close; sql.clear; sql.add(create table pws(user char(20),pwd char(20); ADOQuery1.ExecSQL; sql.clear; sql.add(insert into pws values(a,b); ADOQuery1.ExecSQL; close; END;END;PROCEDURE TForm1.Button2Click(Sender:TObject);BEGIN setCNN(cnnstr); IF checkpwd THEN showmessage(OK) ELSE showmessage(NO);END;END.1

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号