我在主窗体中动态创建子窗体,主窗体上通过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 > 0 then ContainerPanel.Controls[0].Free;
if Assigned(NewForm) then
begin
NewDemo := NewForm.Create(nil);
//调试时发现每次运行到这里后,都要去调用子窗体中的TreeView1Deletion,害得我在子窗体中无法使用Node.Data,为什么?如何解决?
NewDemo.Hide;
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 > 0 then ContainerPanel.Controls[0].Free;
if Assigned(NewForm) then
begin
NewDemo := NewForm.Create(nil);
//调试时发现每次运行到这里后,都要去调用子窗体中的TreeView1Deletion,害得我在子窗体中无法使用Node.Data,为什么?如何解决?
NewDemo.Hide;
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;
解决方案 »
- 解决者200分送上,D6的三层源代码转入到D7,出现“0.0 is not a valid timestamp”,数据库没有定义过timestamp
- 如何把从数据库中查询计算出来的结果保存到另一个表里??
- 关于如何读取不规则格式文件的问题!!!恳请指教
- 高手请进,有关三层问题
- 请教如何设置MDI子窗体的position属性?
- 如何取得日期类型字段月份?
- DELPHI的下载问题,高手请速进
- 请问做一个在线的接收Email的软件, 怎么判断已经邮箱中已经有新的邮件?
- 请教如何作一个类似于IE中的地址栏?是否有此控件?
- CSDN查询系统咨询
- delphi6.0开发的水晶报表在window98下无法运行,求救,十万火急!!!
- 改写一个有关com的程序 发现'type information missing for class TAxxxx'这是啥原应?
procedure MyDeletion(Sender: TObject; Node: TTreeNode);
begin
Dispose(Node.Data);
end;NewDemo := NewForm.Create(nil);
NewDemo.Treeview.OnDeletion := MyDeltion;
...
NewDemo.BorderStyle := bsNone;
要么在TreeView1Deletion加个判断,要么是事先设计好form的BorderStyle