在以模式窗口方式显示的窗口中动态创建控件后再free时,报"abstract error"错误,请问怎么解决?

DumDum 2008-06-11 08:45:44
在以模式窗口方式显示的窗口中动态创建控件后再free时,报"abstract error"错误,请问怎么解决?
例示我的form1窗口以ShowModal方式显示,然后在窗口上创建panel,并在panel上再创建一个button,然后点击button后把panel 给free掉,上时就会报“abstract error"错误,为什么会这样,有什么办法解决吗?
...全文
110 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
DumDum 2008-06-11
  • 打赏
  • 举报
回复
OK,明白了~~!
ysai 2008-06-11
  • 打赏
  • 举报
回复
真要释放,不要用free方法,而用postmessage((sender as tbutton).Parent.handle, WM_CLOSE ,0, 0);
ysai 2008-06-11
  • 打赏
  • 举报
回复
和这个帖子里的问题一样
http://topic.csdn.net/u/20080522/14/5f2e8cce-0c76-46d5-9f69-f9147d9f9f94.html


请看Free方法的帮助:
Warning: Never explicitly free a component within one of its own event handlers or the event handler of a component it owns or contains. For example, don't free a button, or the form that owns the button, in its OnClick event handler.

不要试图在控件的事件中释放自身.
在Button.OnClick中释放它的Parent会把自己也释放了,违反了这个规则
DumDum 2008-06-11
  • 打赏
  • 举报
回复
能在D6中解决吗?公司是用D6做开发的
wywry 2008-06-11
  • 打赏
  • 举报
回复
到这个网站下载个D7或D2007的精简版,D7最小才5M
http://bbs.yd153.com/index.asp?boardid=25
DumDum 2008-06-11
  • 打赏
  • 举报
回复
是delphi 6版本,其他的就不清楚了,是公司别人安装的~~!
ZyxIp 2008-06-11
  • 打赏
  • 举报
回复
楼主你用的版本是火星版的吧。
DumDum 2008-06-11
  • 打赏
  • 举报
回复
Form1要以showmodal方式显示,并且把showmodal结果返回给调用窗口~~!
DumDum 2008-06-11
  • 打赏
  • 举报
回复
Form1要以showmodal方式显示的~~!
wywry 2008-06-11
  • 打赏
  • 举报
回复
我在D2007下调试你的代码,没有问题啊
ZyxIp 2008-06-11
  • 打赏
  • 举报
回复
这样子不会出错啊!!!
DumDum 2008-06-11
  • 打赏
  • 举报
回复
这个还没有说清楚?
就是form1用showmodal方式显示以后,窗口上动态创建一个panel和一个button,点击button后把panel.free;

下面是form1的代码:
unit Unit1;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.ButtonClick(sender:TObject);
begin
if tbutton(sender).Parent.ClassType = tpanel then
(sender as tbutton).Parent.Free ;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Panel1:=TPanel.Create(nil) ;
Panel1.Parent := self;
Panel1.Top := 50;
Panel1.Left :=50;
Panel1.Width := 200;
Panel1.Height := 150;
Button2:=TButton.Create(nil);
Button2.Parent := Panel1;
Button2.OnClick:=ButtonClick ;

end;

end.
ZyxIp 2008-06-11
  • 打赏
  • 举报
回复
你没有说清楚.
7年 2008-06-11
  • 打赏
  • 举报
回复
是因为button1的parent没了吧

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧