R
rsjd
Unregistered / Unconfirmed
GUEST, unregistred user!
不好意思,只有这点分啦,我在主窗体中动态创建子窗体,主窗体上通过tmainmenu的菜单项来建立不同的子窗,子窗体显示在一个TPanel中(代码中的ContainerPanel),现在的问题是子窗体可以建立,但在show的过程中,会自动调用子窗体的onDeletion事件,结果把子窗体中Treeview中的Data全清掉啦,主窗体中的代码如下:
procedure TmainForm.N3Click(Sender: TObject);
begin
ShowForms(TchildForm1)
//TchildForm1是子窗体的type名
end;
procedure TmainForm.ShowForms(NewForm: TFormClass);
var NewDemo: TForm;
begin
if (ContainerPanel.ControlCount=0) or not (ContainerPanel.Controls[0] is NewForm) then
begin
if ContainerPanel.ControlCount &gt
0 then ContainerPanel.Controls[0].Free;
if Assigned(NewForm) then
begin
NewDemo := NewForm.Create(Self);
NewDemo.Hide;
//调试时发现每次运行到这里后,都要去调用子窗体中的TreeView1Deletion,害得我在子窗体中无法使用Node.Data,为什么?
NewDemo.BorderStyle := bsNone;
NewDemo.Parent := ContainerPanel;
NewDemo.Align := alClient;
NewDemo.Show;
end;
end;
end;
子窗体中有一个treeview1,写了一个OnDeletion事件:
procedure TchildForm1.TreeView1Deletion(Sender: TObject
Node: TTreeNode);
begin
Dispose(Node.Data);
end;
procedure TmainForm.N3Click(Sender: TObject);
begin
ShowForms(TchildForm1)
//TchildForm1是子窗体的type名
end;
procedure TmainForm.ShowForms(NewForm: TFormClass);
var NewDemo: TForm;
begin
if (ContainerPanel.ControlCount=0) or not (ContainerPanel.Controls[0] is NewForm) then
begin
if ContainerPanel.ControlCount &gt
0 then ContainerPanel.Controls[0].Free;
if Assigned(NewForm) then
begin
NewDemo := NewForm.Create(Self);
NewDemo.Hide;
//调试时发现每次运行到这里后,都要去调用子窗体中的TreeView1Deletion,害得我在子窗体中无法使用Node.Data,为什么?
NewDemo.BorderStyle := bsNone;
NewDemo.Parent := ContainerPanel;
NewDemo.Align := alClient;
NewDemo.Show;
end;
end;
end;
子窗体中有一个treeview1,写了一个OnDeletion事件:
procedure TchildForm1.TreeView1Deletion(Sender: TObject
Node: TTreeNode);
begin
Dispose(Node.Data);
end;