看看我寫的代碼該怎樣修改才可以做到進入界面2時關掉界面1:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Panel2: TPanel;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
unit2;
{$R *.DFM}
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bitbtn1.enabled:=false;
Edit1.text:='';
Edit2.text:='';
BitBtn1.Enabled:=false;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
if length(edit1.Text)=6 then
form1.FocusControl(Edit2);
//edit2.text:='******';
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
if (edit1.text='123456') and (edit2.text='000000') then
begin
bitbtn1.enabled:=true;
form1.focuscontrol(bitbtn1);
MODALRESULT := MROK
end;
if (edit1.text<>'123456') and (edit2.text<>'000000') then
begin
MODALRESULT := MRCancel;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
//showmessage('歡迎使用!');
form2.ShowModal;
form1.close;
//MODALRESULT := MROK
end;
procedure tform1.edit1keypress(sender: tobject; var key: char);
begin
if not (key in['0','1','2','3','4','5','6','7','8','9',#8]) then
begin
key:=#0;
messagebeep(1);
end;
end;
end.
***************************
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, Grids, Calendar;
type
TForm2 = class(TForm)
Calendar1: TCalendar;
Timer1: TTimer;
BitBtn1: TBitBtn;
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
Label1: TLabel;
RadioGroup1: TRadioGroup;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Edit2: TEdit;
Button3: TButton;
Button4: TButton;
Bevel3: TBevel;
Image1: TImage;
procedure BitBtn1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
close;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
form2.edit1.text:=timetostr(time);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
//MODALRESULT := MROK
end;
end.