我这样做不要那两行程序也可以运行,但不知有什么后果.
////////////////////////////////////////////////////////////////
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas';
{$R *.res}
begin
// Application.Initialize;
if LoadOk then Form1Create
//LoadOk来自Unit2,Form1Create来自Unit1.
// Application.Run;
end.
////////////////////////////////////////////////////////////////
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function LoadOk : boolean;
var
Form2: TForm2;
implementation
{$R *.dfm}
function LoadOk;
begin
with TForm2.Create(nil) do
begin
result := ShowModal=mrok;
free;
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if (edit1.Text = '1') and (edit2.Text = '1') then
begin
ModalResult:=mrok;
end
else
begin
application.MessageBox(pchar('密码不对,请重新输入.'),pchar(application.Title),MB_OK+MB_ICONWARNING);
ModalResult:=mrnone;
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
ModalResult:=mrcancel;
end;
end.
/////////////////////////////////////////////////////////////////
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
procedure Form1Create;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Form1Create;
begin
with TForm1.Create(nil) do
begin
ShowModal;
free;
end;
end;
end.
///////////////////////////////////////////////////////////////////////