Anonymous
2008-10-21 15:19:22 UTC
I have been unable to understand the inherited clause for many years.
As a result of an explanation given for another problem I was having
recently, I have been able to come up with an understanding of what
this clause means and am going to put out my simplified definition
here. Any correction is welcome.
What inherited infers is basically this: Do what you would have
normally done if I had not taken control of the situation.
An example can be seen below.
------------------------------------------------------------------------
public
{ Public declarations }
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_CLOSE) then begin // X button clicked in
upper right hand corner of program interface
...do what needs to be done
end
else
inherited; //inherited means to do what you would have
otherwise done
end;
------------------------------------------------------------------------
--------------------
If the 'else inherited;' had not been placed at the end of the
WMSysCommand procedure, any other sys command messages (example:
SC_MINIMIZE, SC_MAXIMIZE, SC_RESTORE) would have been captured by the
WMSysCommand procedure and would have simply been ignored. As a result
of the presents of the inherited statement, all other sys command
messages are processed as usual as if the WMSysCommand procedure were
not present.
As a result of an explanation given for another problem I was having
recently, I have been able to come up with an understanding of what
this clause means and am going to put out my simplified definition
here. Any correction is welcome.
What inherited infers is basically this: Do what you would have
normally done if I had not taken control of the situation.
An example can be seen below.
------------------------------------------------------------------------
public
{ Public declarations }
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_CLOSE) then begin // X button clicked in
upper right hand corner of program interface
...do what needs to be done
end
else
inherited; //inherited means to do what you would have
otherwise done
end;
------------------------------------------------------------------------
--------------------
If the 'else inherited;' had not been placed at the end of the
WMSysCommand procedure, any other sys command messages (example:
SC_MINIMIZE, SC_MAXIMIZE, SC_RESTORE) would have been captured by the
WMSysCommand procedure and would have simply been ignored. As a result
of the presents of the inherited statement, all other sys command
messages are processed as usual as if the WMSysCommand procedure were
not present.