Delphi, override custom control setcaption

I have a custom control,
the ancestor is another custom control,
whose ancestor is TPanel;
that is

< p>

TNotMyCustomControl = class(Tpanel);

TMyCustomControl = class(TNotMyCustomControl);

Whether you can react when setting the title (runtime or Design time), and still pass the changes to the Ancestor control?

It’s possible. Just add the CMTextChanged message handler to the custom TPanel:

type
TMyPanel = class(TPanel)
private
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
end;

{ ... }

procedure TMyPanel.CMTextChanged(var Message: TMessage);
begin
inherited;
ShowMessage ('caption has been changed');
end;

I have a custom control,
The ancestor is another custom control,
Whose ancestor is TPanel;
ie

TNotMyCustomControl = class(Tpanel);

TMyCustomControl = class(TNotMyCustomControl);

Is it possible to react when setting the title (run time or design time) and still pass the changes to the Ancestor control?

It is possible. Just add the CMTextChanged message handler to the custom TPanel:

< pre>type
TMyPanel = class(TPanel)
private
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
end;

{. .. }

procedure TMyPanel.CMTextChanged(var Message: TMessage);
begin
inherited;
ShowMessage(‘caption has been changed’);
end;

Leave a Comment

Your email address will not be published.