表格 – 德尔福登录表格
发布时间:2020-12-15 09:09:35 所属栏目:大数据 来源:网络整理
导读:在我的Delphi程序中,我有一个登录表单,它在创建主表单之前显示,但我面临的问题是我想登录检查在主表单中处理,这意味着登录表单将使用要检查并继续的主要表格, 请阅读以下评论: procedure LogInButtonClick(Sender: TObject) ; 这是TLoginForm代码(from delp
在我的Delphi程序中,我有一个登录表单,它在创建主表单之前显示,但我面临的问题是我想登录检查在主表单中处理,这意味着登录表单将使用要检查并继续的主要表格,
请阅读以下评论:
这是TLoginForm代码(from delphi.about.com): unit login; interface uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls; type TLoginForm = class(TForm) LogInButton: TButton; pwdLabel: TLabel; passwordEdit: TEdit; procedure LogInButtonClick(Sender: TObject) ; public class function Execute : boolean; end; implementation {$R *.dfm} class function TLoginForm.Execute: boolean; begin with TLoginForm.Create(nil) do try Result := ShowModal = mrOk; finally Free; end; end; procedure TLoginForm.LogInButtonClick(Sender: TObject) ; begin if passwordEdit.Text = 'delphi' then { Here how it's possible to use : if MainForm.text=passwordEdit.Text then ModalResult := mrOK } ModalResult := mrOK else ModalResult := mrAbort; end; end. 这是主程序初始化流程: program PasswordApp; uses Forms,main in 'main.pas' {MainForm},login in 'login.pas' {LoginForm}; {$R *.res} begin if TLoginForm.Execute then begin Application.Initialize; Application.CreateForm(TMainForm,MainForm) ; Application.Run; end else begin Application.MessageBox('You are not authorized to use the application. The password is "delphi".','Password Protected Delphi application') ; end; end. 谢谢 解决方法
如果您需要首先创建主表单,请先创建它:
begin Application.Initialize; Application.CreateForm(TMainForm,MainForm);//created,but not shown if TLoginForm.Execute then//now the login form can refer to the main form Application.Run//this shows the main form else Application.MessageBox('....'); end; 这是你提出的问题的直接和天真的答案.更广泛地思考,我鼓励您将登录测试移出主表单.把它放在任何更高级代码需要使用的地方.您目前正在努力的设计具有不健康的耦合. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |