[SOLVED] Component name lazarus / 31-LCL ---------------------------------------------------------------------- pcurtis · 2022-02-15 16:06 I have a small cosmetic problem. I made a component (see ripped down version below). My issue is this - When, normally, at design time a visual is dropped on a form it is given a name and the name is copied to the caption property. If the caption is edited in the OI the components name remains the same but the caption of the component on the form changes. How do I do that? (The same behavior can be seen in a Groupbox for exanple) In my example the name and caption is drawn on the canvas. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TMyTest = class(TCustomControl)  private    fCaptionText: String;    procedure SetCaption(const AValue: String);  protected    procedure Paint; override;  public    constructor Create(AOwner : TComponent); override;  published    property Caption: String read fCaptionText write SetCaption;  end; procedure Register; implementation constructor TMyTest.Create(AOwner : TComponent);begin  inherited Create(AOwner);   SetInitialBounds(0, 0, 200, 200);end; procedure TMyTest.SetCaption(const AValue: String);begin    Invalidate;end; procedure TMyTest.Paint;var  sTemp: String;begin  inherited Paint;   if not(csDesigning in ComponentState) then    begin      fCaptionText:= Name;    end  else    begin      fCaptionText:= 'Name1';    end;   Canvas.TextOut(10, 1, fCaptionText);end; ---------------------------------------------------------------------- winni · 2022-02-15 16:24 And the question is ????? ---------------------------------------------------------------------- pcurtis · 2022-02-15 16:34 Oops, it does help. Changed OP. ---------------------------------------------------------------------- pcurtis · 2022-02-20 09:53 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit MyGroupbox; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,  StdCtrls, ComCtrls; type   TMyGroupbox= class(TCustomControl)  private    fCaption: String;    fCaptionAsName: Boolean;    procedure SetCaption(Value: String);  protected    procedure SetName(const NewName: TComponentName); override;    procedure Paint; override;  public    constructor Create(AOwner: TComponent); override;  published    property Caption: String read fCaption write SetCaption;  end; procedure Register; {$R mygroupbox.res} implementation constructor TMyGroupbox.Create(AOwner: TComponent);begin  inherited Create(AOwner);  if (AOwner as TControl).Color = clDefault then    Color:= clBtnFace  else    Color:= (AOwner as TControl).Color;  ControlStyle:= ControlStyle + [csOpaque, csReplicatable, csSetCaption, csAcceptsControls];  fCaptionAsName:= (csDesigning in ComponentState) and                   not (csReadingState in ControlState);  SetInitialBounds(0, 0, 200, 104);end; procedure TMyGroupbox.SetName(const NewName: TComponentName);begin  if fCaptionAsName then  begin    fCaptionAsName:= fCaption = Name;    fCaption:= NewName;    invalidate;  end;  inherited SetName(NewName);end; procedure TMyGroupbox.SetCaption(Value: String);begin  if fCaption <> Value then  begin    fCaption:= Value;    invalidate;    fCaptionAsName:= False;  end;end; procedure TMyGroupbox.Paint;var  iHeight: Integer;  iWidth: Integer;begin  inherited Paint;   Canvas.Clear;   iHeight:= Canvas.TextHeight(fCaption);  iWidth:= Canvas.TextWidth(fCaption);   if Enabled then    begin      Canvas.Pen.Color := clBlack;    end  else    begin      Canvas.Pen.Color := cl3DShadow;    end;   Canvas.Line(0, iHeight div 2, 5 ,iHeight div 2);  Canvas.Line(0, iHeight div 2, 0 ,Height-1);  Canvas.LineTo(Width - 1, Height - 1);  Canvas.LineTo(Width - 1, iHeight div 2);   if fCaption <> '' then    Canvas.LineTo(15 + iWidth, iHeight div 2)  else    Canvas.LineTo(0, iHeight div 2);   Canvas.Brush.Color:= Color;   Canvas.TextOut(10, 1, fCaption);end; procedure Register; begin  RegisterComponents('Misc',[TMyGroupbox]);end; end.