//在自定义消息中使用关键字inherited;procedure TfrmMain.SXMyMessage(var Msg:TMessage);
begin
inherited;
end;//inherited起到什么作用,他继承了什么?继承了那个函数?
begin
inherited;
end;//inherited起到什么作用,他继承了什么?继承了那个函数?
解决方案 »
- 关于不同分辨率下的窗体大小问题
- 启动后直接最小化到托盘栏
- 请教处理数据时的进度显示是怎么实现的?
- 菜鸟问题:如何连接到远程SQL Server服务器?(up也有分)
- 怎样实现鼠标拖动image的效果?
- 用rawsocket编写ping功能代码,用select设置超时设置timeval.tv_sec := 0时全部ping所有ip都超时 ?
- chechy,老鱼,老千,小新,老龟,x空间,凡是认识 牛虻 的,请来留个qq,方便联系,多谢//牛虻
- 有多少人使用DB2数据库?(调查)
- delphi5中如何打印剪贴板图象!!!
- GlScene如何实现缩放平移、旋转等操作?
- Delplhi应用程序中如何打开.htm文件
- 关注,关注!高手来看!
因为VCL的消息处理机制,消息到达处理该消息的过程后,经过处理过程的处理和inherited句,消息来到对象的Defaulthandler().这个方法对消息进行最后的处理.
如果不用inherited就不能进行常规的消息处理.DDG5里的消息处理机制里说得应该还算清楚,去看看吧!
When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method. In this case, inherited can appear with or without parameters; if no parameters are specified, it passes to the inherited method the same parameters with which the enclosing method was called. For example,inherited;occurs frequently in the implementation of constructors. It calls the inherited constructor with the same parameters that were passed to the descendant.
以上话是对reallike(此人已删除) 讲的, 请参考
When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method. In this case, inherited can appear with or without parameters; if no parameters are specified, it passes to the inherited method the same parameters with which the enclosing method was called. For example,inherited;occurs frequently in the implementation of constructors. It calls the inherited constructor with the same parameters that were passed to the descendant.
在delphi的消息处理中,inherited并不是必须要有的。在wndpro中,我们可以得到所有的消息,以为我们只关心其中的几个消息,所以,对于其他的消息处理我们都交给父类完成。以保证程序的正确运行。但是在某写时候,需要彻底的屏蔽掉一个消息,也就是岁、所谓的消息陷阱。这个时候,我们根本不需要什么inherited。还有就是要考察父类提供的消息处理方式是否对我们有用,如果有用,可以使用inherited来减少代码。例如tcustomedit中按下vk_left光标向左移动。如果想向右移动,那么如何inherited呢?最后就是自定义的消息的响应,父类中根本没有响应的处理函数,又如何inherited呢?
procedure TfrmMain.SXMyMessage(var Msg:TMessage);
begin
inherited SXMyMessage(Msg);
//或者inherited 父类提供的任何可见的方法(需要的参数);
end;
直接写inherited;表示调用父类中相同名字的方法。如果它是重载的则必须写完整,否则编译器不知道调用哪一个重载的方法。
2、inherited并不局限于消息处理中使用,实际上在任何地方都可以使用它。意思就是调用父类的某个方法。例如:
procedure TForm1.Button1Click(Sender: TObject);
begin
inherited Close;
end;
3、因为inherited只是调用父类的某个方法,因此如果不需要使用这个调用时,那么就没有必要使用inherited。不过 fengjn(小枫) 的说法是不准确的。在大多数时候即使父类没有处理这类消息,也往往应该加上inherited语句,因为父类的处理在将来完全是可能要修改的。————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
你失望什么,是你自己理解不够深刻吧, 我讲得不对吗, 请指正。你把能在他的父类中找到:procedure SXMyMessage(var Msg:TMessage);吗?
你把 inheried 注掉试试是不是一样to: pressman(还穿三角裤)
骂人是我不对, 没办法火气太大了,真的快爆了
==================================================================================
http://expert.csdn.net/Expert/topic/2123/2123513.xml?temp=.3029749
帮忙UP两把
pressman(还穿三角裤) 是你什么人????我觉得fengjn(小枫) 说的在理, pressman(还穿三角裤) 有一部分在理
共同进步才是目的。
begin
inherited; //在这里设置一个断点
end;project->options->compiler->debugging 选择Use Debug DCUs
然后F7单步调试,你自己应该可以看到答案了
begin
inherited; //在这里设置一个断点
end;project->options->compiler->debugging 选择Use Debug DCUs
然后F7单步调试,你自己应该可以看到答案了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
const
UM_Test = WM_USER + 100;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure MyMessage(var Msg: TMessage); message UM_Test;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}{ TForm1 }procedure TForm1.MyMessage(var Msg: TMessage);
begin
//inherited;
ShowMessage('Hello');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Perform(UM_Test, 0, 0);
end;end.
begin
inherited;
ShowMessage('Hello');
end;我要的就是把这两个‘/’给我删除,这个inherited到底在干什么。你答非所问!唉……
begin
inherited;
ShowMessage('Hello');
end;
,这里应该是调用TFORM1的祖先tcustomform的消息处理,由于tcustomform没有这个实现,所以直接调用的是tcustomform的defaulthandle.
好好,说人家放屁,倒是弄出点证据说人家到底放了哪门子屁?自己倒是弄出个正确的解释给我听听?这算什么人?唉,不求甚解我昨天晚上和549弄了好长时间,我们都知道inherited的基本意思。但是在自定义消息过程里面就不一样了!所以找个合理的解释!
begin
inherited;
ShowMessage('Hello');
end;
在message处理中和其他不一样的是inherited不会因为没有在祖先中找到一样的函数或者方法而将inherited失效,他会传入缺省的消息处理.
这里调用TFORM1的祖先的消息处理,由于tform和tcustomform没有这个实现,所以直接调用的是tcustomform的defaulthandle.(注意这个方法是对twincontrol的override)
另外,风炎老大,我再问一下,消息在dispatch激活,到底在哪里结束呢?
procedure TForm1.MyMessage(var Msg: TMessage);
begin
inherited;
ShowMessage('Hello');
end;
procedure TForm1.MyMessage(var Msg: TMessage);
begin
ShowMessage('Hello');
end;
procedure TForm1.MyMessage(var Msg: TMessage);
begin
ShowMessage('Hello');
inherited;
end;
看出来。在我的使用来讲,我可能会在defaulthandle中集中的处理消息产生的垃圾。
system单元里TObject.Dispatch的asm代码,你应该看起来没有问题啊
GetDynaMethod或者defaulthandle的调用
Microsoft OLE DB Provider for SQL Server 错误 '80040e31' 超时已过期 /Expert/reply.asp,行105
begin
end;:(空的!空的!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 DefaultHandler是虚函数阿,在虚表中vmtDefaultHandler,他调用的具体的TForm1类虚表中的DefaultHandler
我针对你干嘛, 我针对那个老冤家
最终都是windows回收,关键是你应该在什么时候释放结构的资源,只有自己决定
to: reallike(此人已删除)
不好意思,csdn太火爆,帖子一下就沉了,什么时候能拜读一下第二版?:)
to: DWGZ()
csdn上没有冤家,更没有老冤家了,每个人都有自己的理解,兄台不必介意,看外面还有那么多朋友在叫help,不要在这里斗嘴了:)
这种情况属于自定义消息,父类中根本找不到,你这里加不加inherited都是一样,没加VCL自己会处理, 你们看到的情况也就是VCL自己内部处理的情况。 当它向父类中向后查找到这个消息句柄, 你这个inherited 才起作用, 所以你这里加不加inherited 都一样,
你换个你父类中可以找到的消息试试, 白痴
Base Class的相對的Message Handle,就去Call DefaultHandle,TMD,狗輩OO.
http://expert.csdn.net/Expert/topic/2123/2123757.xml?temp=.3006861
看誰能有一個好的解決方法,這在C++中是最基本的東西,在OP(不如叫GP->狗屁)卻
好辦,我無意說Delphi與C++誰好誰弱,我在學Delphi了
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————