在我的Delphi程序,我登录表单,它的显示在主窗体之前被创建,但我现在面临的问题是,我想登录检查的主要形式进行处理,这意味着登录表单将使用主窗体检查和进行,
请阅读放在评论:
程序LogInButtonClick(发信人:TObject的);
这里是TLoginForm码( 从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.
谢谢