大俠們請幫忙想想!(100分)

  • 主题发起人 主题发起人 james998
  • 开始时间 开始时间
J

james998

Unregistered / Unconfirmed
GUEST, unregistred user!
做了一個用戶界面1及界面2,當執行界面1時輸入正確的密碼則進入界面2。注意問題來了:
輸入正確的密碼進入了界面2,可是要怎樣才能關掉界面1?傷腦筋....
 
哈哈这还不简单啊!!
若是界面1不是多文档窗口的子窗口!
只需在进入界面2的地方,写MODALRESULT := MROK

若是界面1是多文档窗口的子窗口 ,则
只需在进入界面2的地方,写CLOSE ;
 
单文档呢?
 
TO:cfx
你提出的解決方法只可以在退出界面2的時候關掉界面1,而在剛進入界面2則也無法關掉。
再想想...試試.....
 
你可以把Form1设置为ShowModal.若密码正确则把MODALRESULT := MROK
若不正确则把MODALRESULT := MRCancel.对于Modal对话框,只要把MODALRESULT
设置为MROK或MRCancel,则Modal对话框自动关闭与释放。
if form1.showmodal=MROK then
form2.show;
也就是说是关闭了Form1后对打开Form2.
 
看看我写的这个:
注意:MainForm自己释放!!!!

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {MainForm},
Unit2 in 'Unit2.pas' {PWDForm};

{$R *.res}

var
PWDForm : TPWDForm;

begin
Application.Initialize;
PWDForm := TPWDForm.Create(Application);
if PWDForm.ShowModal = PWDForm.Passbtn.ModalResult then
Application.CreateForm(TMainForm, MainForm);
PWDForm.Free;
Application.Run;
end.


*******************************************************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TMainForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.dfm}

end.
************************************8
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TPWDForm = class(TForm)
Passbtn: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;

var
PWDForm: TPWDForm;

implementation

{$R *.dfm}

end.
******************88
 
TO:dongberlin
你提出的解決方法無法關掉............
我做的進入鍵是要輸入正確的密碼則激活,否則無法進入。
 
看看我寫的代碼該怎樣修改才可以做到進入界面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.

 
你不用ModalResult来判断还不是可以,TPSWForm里面设置一个判断
integer变量。如果密码通过就给一个值(比如0),不通过就给1,
然后project单元里面判断是不是0,是就创建mainform,不通过就结束程序
或者做别的,接着PWDForm.free ;
 
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
//showmessage('歡迎使用!');
form2.ShowModal;
form1.close;

//MODALRESULT := MROK

end;

@@@@@@@@@

Don't Create Form2 here,but Create it in projiect unit

and return the value of ModalResult or the
sign you set
 
請幫忙修改因急著用,順便在提一下:要使窗口的放大功能失控怎么做.....
 
1.关掉放大功能:
如果想做无标题栏的窗口则只要在设bordericon为空,borderstyle=bsSingle;
如果不是则在OnCanResize中Resize=false;
2.听你的意思只不过是想在程序一开始的时候要求别人录入密码,你应该在项目程序
中做这件事:
program em;

uses
Forms,
windows,
emMain in 'emMain.pas' {winMain},
emLogin in 'emLogin.pas' {winLogin},
. . .
. . .
. . .

{$R *.RES}

var
LogOk: Boolean;

begin
Application.Initialize;
winLogin := TwinLogin.Create(Application);
winLogin.ShowModal;
LogOk := winLogin.LogOk;
winLogin.Free;
if not LogOk then Application.Terminate else begin
Application.CreateForm(TwinMain, winMain);
Application.Run;
end;
end.

=======
这里, winLogin就是你的form1, winMain就是你的form2.
这是从我的应用系统中拷出来的,绝对可行。
 
Kisber, LogOk := winLogin.LogOk;这句是什么意思.
 
還是沒解決問題,不過還是要謝謝你們。。。。。
 
老天阿!还没解决?Kisber,的代码那么清楚!他的思想就好像我说的设置一个标志嘛!
LogOK就这这样啊!密码通过就给个True.否则False.

不知道你到底要什么样的结果! ???@%^@$%&@$%


 

Similar threads

后退
顶部