資源描述:
《delphi dll封閉窗體登錄封裝到DLL的例子》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、Delphi登錄封裝到DLL這是一個把登錄封裝到DLL的例子,當前程序還包括自動建立數(shù)據(jù)庫,給數(shù)據(jù)庫加密碼。UNITfrm_pws;INTERFACEUSESWindows,SysUtils,Controls,Forms,DB,ADODB,Classes,StdCtrls;TYPETfrmpws=CLASS(TForm)Label1:TLabel;Edit1:TEdit;Label2:TLabel;Edit2:TEdit;Button1:TButton;Button2:TButton;ADOQuery1:TADOQuery;PROCEDUREButton
2、1Click(Sender:TObject);PROCEDUREButton2Click(Sender:TObject);PRIVATE{Privatedeclarations}PUBLIC{Publicdeclarations}END;VARfrmpws:Tfrmpws;logincount:integer;IMPLEMENTATION{$R*.dfm}PROCEDURETfrmpws.Button1Click(Sender:TObject);VARsql:STRING;BEGINsql:='select*frompws'+'whereuser="'+
3、edit1.Text+'"'+'andpwd="'+edit2.Text+'"';ADOQuery1.SQL.Text:=sql;ADOQuery1.Active:=true;inc(logincount);6IF(logincount>4)THENself.ModalResult:=mrcancelELSEBEGINIFNOTADOQuery1.IsEmptyTHENBEGINModalResult:=mrok;ADOQuery1.Active:=false;ENDELSEBEGINedit1.Text:='';edit2.text:='';END;E
4、ND;END;PROCEDURETfrmpws.Button2Click(Sender:TObject);BEGINModalResult:=mrcancel;END;END.LIBRARYpws;{ImportantnoteaboutDLLmemorymanagement:ShareMemmustbethefirstunitinyourlibrary'sUSESclauseANDyourproject's(selectProject-ViewSource)USESclauseifyourDLLexportsanyproceduresorfunction
5、sthatpassstringsasparametersorfunctionresults.ThisappliestoallstringspassedtoandfromyourDLL--eventhosethatarenestedinrecordsandclasses.ShareMemistheinterfaceunittotheBORLNDMM.DLLsharedmemorymanager,whichmustbedeployedalongwithyourDLL.ToavoidusingBORLNDMM.DLL,passstringinformation
6、usingPCharorShortStringparameters.}USESSysUtils,6Classes,Controls,frm_pwsIN'frm_pws.pas'{frmpws};VARmyCnn:STRING;{$R*.res}FUNCTIONcheckpwd:boolean;STDCALL;VARfrmpws:tfrmpws;BEGINIFmycnn=''THENBEGINresult:=false;exit;ENDELSEBEGINfrmpws:=tfrmpws.Create(NIL);TRYfrmpws.ADOQuery1.Conn
7、ectionString:=mycnn;result:=frmpws.ShowModal=mrok;FINALLYfrmpws.free;END;END;END;PROCEDUREsetCNN(cnn:STRING);STDCALL;BEGINmyCnn:=cnn;END;EXPORTSsetCNN,checkpwd;BEGINEND.programProject1;usesForms,Unit1in'Unit1.pas'{Form1};{$R*.res}begin6Application.Initialize;Application.CreateFor
8、m(TForm1,Form1);Application.Run;end.UNIT