给段窗体关闭重新打开的代码 Form1中有个Button1按了Button1效果是Form1关闭了,然后又重新打开了。前提:是关闭,不是简单的HIDE SHOW代码要运行通过的。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Close; ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL); ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL); Close; 你的回答中,要是程序只有一个窗体下是可能会对,但我的Form1只是程序中的一个普通窗体,不是主窗体!而且这个代码,我放在不同地方不一定结果一样! 那你为什么要CLOSE不要HIDE? hide的话,窗体的代码不会再重新构建就是说里面用到变量的话,貌似是不会改变的,有用到数据库连接的。我想要的就是先关了,再打开。HIDE SHOW行的话,我也就不会发帖求救了 如果只是有变量的话,那就简单了,也不必这么复杂了,关键还是找一个好的思路来解决问题。可以自己建立一个pas单元,把变量放在里面。 Close; TForm(ClassType.NewInstance).Create(Owner).Show;不过从问问题的方式看,你用这段代码还会出现别的问题的 只能說你的思路是個錯誤的。實再不行,你就先創建一個新的,再CLOSE,反正看情形,你是想清楚這個窗體下的變量。 form1:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Unit3;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } procedure OpenForm2(var Msg: TMessage); Message WM_USER01; public { Public declarations } end;var Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.OpenForm2(var Msg: TMessage);begin if not assigned(form2) then form2 := TForm2.create(Application); form2.showmodal; form2.free; form2 := nil;end;procedure TForm1.Button1Click(Sender: TObject);begin PostMessage(Form1.Handle, WM_USER01, 0, 0);end;end.form2:unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm2 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form2: TForm2;implementationuses Unit1, Unit3;{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);begin Close; PostMessage(Form1.Handle, WM_USER01, 0, 0);end;end.unit3:unit Unit3;interfaceuses Messages;const WM_USER01 = WM_USER + 8001;implementationend.不知这样是否可以满足你的要求 FreeAndNil(Form1);Form1 := TForm1.Create(Application); ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL);Close; Application.Terminate;ShellApi.ShellExecute(Application.Handle,'Open', PChar(Application.exeName),GetCommandLineA,'',SW_SHOWNORMAL); delphi 里面的时间计算问题 升到5个三角了,向星级冲刺,散分! adoconnection对象打开无法操作的问题 菜鸟还请各位高手帮忙 当窗体最大化时,如何让可视化控件随之按比例最大化 请问如何能将strtoint引发的异常屏蔽掉!! pb调用delphi动态库的函数(var aaaa:PChar)?????? 青岛的程序员看过来 delphi TEdit透明 为什么有些系统函数如AllocateHWnd在DEPHI HELP中找不到?如何找到想要的API函数? 关于用ADOquery更新的问题 去年5.15日到现在又是一年,时间过的真快!
Close;
ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL);
ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL);
Close;
而且这个代码,我放在不同地方不一定结果一样!
就是说里面用到变量的话,貌似是不会改变的,有用到数据库连接的。
我想要的就是先关了,再打开。HIDE SHOW行的话,我也就不会发帖求救了
Close;
TForm(ClassType.NewInstance).Create(Owner).Show;不过从问问题的方式看,你用这段代码还会出现别的问题的
form1:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Unit3;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure OpenForm2(var Msg: TMessage); Message WM_USER01;
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.OpenForm2(var Msg: TMessage);
begin
if not assigned(form2) then
form2 := TForm2.create(Application);
form2.showmodal;
form2.free;
form2 := nil;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Form1.Handle, WM_USER01, 0, 0);
end;end.form2:
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementationuses Unit1, Unit3;{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
Close;
PostMessage(Form1.Handle, WM_USER01, 0, 0);
end;end.unit3:
unit Unit3;interface
uses Messages;
const
WM_USER01 = WM_USER + 8001;implementationend.不知这样是否可以满足你的要求
Form1 := TForm1.Create(Application);
Close;
ShellApi.ShellExecute(Application.Handle,'Open', PChar(Application.exeName),GetCommandLineA,'',SW_SHOWNORMAL);