首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

创建窗体的有关问题,很奇怪的

2012-03-01 
创建窗体的问题,很奇怪的!//我动态创建两个窗体Form1 : TForm1.Create(Application)Form2 : TForm1.Cre

创建窗体的问题,很奇怪的!
//我动态创建两个窗体
Form1 := TForm1.Create(Application);
Form2 := TForm1.Create(Application);

//然后释放Form1
Form1.Free;

//这时Form2也变为nil了
if Form2 <> nil then
ShowMessage('not nil');

//请问这到底为什么啊?如果我要像这样创建一个窗体的两个实例应该怎么办?因为Form2创建后Form1的指针就变成野指针了


[解决办法]
能不能先不释放或调整顺序
[解决办法]
不会啊!我是这样写的,lz看看!

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
form2 :TForm1;
form3 : TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
form2:=TForm1.Create(self);
form3 := TForm1.Create(self);
form2.Show;
form3.Show;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
form2.Free;
end;

end.

热点排行