主界面: procedure TmainForm.ButtonOnClick(Sender:TObject); begin Form1 := TForm1.Create(Self); Form1.ShowModal; If Form1.cmdSave.ModalResult = mrOK then begin Form1 := TForm1.Create(Selft); Form1.ShowModal; end; end;Form1: procedure TForm1.cmdSaveOnClick(Sender: TObject); begin ...... ..... ..... cmdSave.ModalResult := mrOK; end;procedure TForm1.Form1OnClose(...); begin ....... ...... Action := caFree; end;
Form1 button1显示Form2 有timer控制Form2在关闭后1秒再显示,初始timer.enable:=False; unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Button1: TButton; Timer1: TTimer; procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation uses Unit2; {$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject); begin Form2.Show; end;procedure TForm1.Button1Click(Sender: TObject); begin Form2.Show; end;end.Form2//关闭按钮,关闭后会自动显现,Button1关闭后不再显示 unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm2 = class(TForm) Button1: TButton; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form2: TForm2; Flag:Boolean=True; implementation uses Unit1; {$R *.dfm}procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction); begin if Flag then Unit1.Form1.Timer1.Enabled:=True; end;procedure TForm2.FormShow(Sender: TObject); begin Unit1.Form1.Timer1.Enabled:=False; end;procedure TForm2.Button1Click(Sender: TObject); begin Flag:=False; Close; end;end.
可是CLOSE的时候自然会产生CLOSE事件,所以关不掉procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction); begin if Flag then Unit1.Form1.Timer1.Enabled:=True; end;
实现数据的更新也不至于要频繁的打开关闭窗口啊,你可以直接写一个刷新函数嘛
另外,如果你实在是想这样的话,Form1.Hide,然后再Form1.Show,不过好像意义不大
1、AdoQuery.Close;
AdoQuery.Open;
2、AdoQuery.Refresh;
--------------------------------------
靠,还不结帖!
procedure TmainForm.ButtonOnClick(Sender:TObject);
begin
Form1 := TForm1.Create(Self);
Form1.ShowModal;
If Form1.cmdSave.ModalResult = mrOK then
begin
Form1 := TForm1.Create(Selft);
Form1.ShowModal;
end;
end;Form1:
procedure TForm1.cmdSaveOnClick(Sender: TObject);
begin
......
.....
.....
cmdSave.ModalResult := mrOK;
end;procedure TForm1.Form1OnClose(...);
begin
.......
......
Action := caFree;
end;
button1显示Form2
有timer控制Form2在关闭后1秒再显示,初始timer.enable:=False; unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses Unit2;
{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin
Form2.Show;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;end.Form2//关闭按钮,关闭后会自动显现,Button1关闭后不再显示
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
Flag:Boolean=True;
implementation
uses Unit1;
{$R *.dfm}procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Flag then
Unit1.Form1.Timer1.Enabled:=True;
end;procedure TForm2.FormShow(Sender: TObject);
begin Unit1.Form1.Timer1.Enabled:=False;
end;procedure TForm2.Button1Click(Sender: TObject);
begin
Flag:=False;
Close;
end;end.
begin
if Flag then
Unit1.Form1.Timer1.Enabled:=True;
end;