Jump to content
Sign in to follow this  
Zakaria

how to correct this Code

Recommended Posts

Method 'SetText' not found in base class
 

interface
Uses VCL.ExtCtrls,VCL.Controls;
Type
  TPanel1 = class(TPanel)
  private
    Procedure SetEnabled(Value: Boolean);     override;
    Procedure SetText(const Value: TCaption); override;

  public

  End;

implementation


{ TPanel1 }

procedure TPanel1.SetEnabled(Value: Boolean);
begin
  inherited;

end;

procedure TPanel1.SetText(const Value: TCaption);
begin
  inherited;

end;

 

Share this post


Link to post
  1. SetText is declared private in the TControl base class so you don't have access to it.
  2. SetText is not declared virtual so you cannot override it.

My guess is that you instead need to handle the WM_SETTEXT message.

Share this post


Link to post
3 hours ago, Zakaria said:

how to correct

 

Well, what do you want to achieve here?

 

Look at the source code  for TControl, from which TPanel inherits the Caption property and its SetText and GetText accessor methods.

procedure TControl.SetTextBuf(Buffer: PChar);
begin
  Perform(WM_SETTEXT, 0, Buffer);
  Perform(CM_TEXTCHANGED, 0, 0);
end;

Setting a control's Caption or Text properties ends up sending messages to the control. WM_SETTEXT stores the passed string and CM_TEXTCHANGED is a notification for the control that the caption or content has changed, which typically makes the control redraw itself.

TCustomPanel, the immediate ancestor of TPanel, has a private message handler

    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;

that just calls Invalidate to redraw the panel. If you want to react to a change of the panel Caption you have to add a handler for this message to your modified TPanel class. You cannot override the parent method since it is not virtual or dynamic and also private. But you can call the inherited message handler inside your handler using the inherited keyword.

 

If you just want a panel that does not show the Caption: it has a ShowCaption property that you can set to false to achieve that. You could set that in an overridden Loaded method.

Share this post


Link to post
7 hours ago, Zakaria said:

how to correct

There seems to be a pretty big gap between your knowledge and your ambitions and you shouldn't really be trying to make custom components (or whatever it was you did) if you haven't learned about things like polymorphism and scope.

 

I suggest you start with something more basic.

  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×