[SOLVED] Component caption lazarus / 31-LCL ---------------------------------------------------------------------- pcurtis · 2021-11-08 18:04 Consider this simple component based on TLabel. It has a property Time. How can I display the property Time instead of the component name during run and design time? 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 MyCounter; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Stdctrls, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls; type   TMyCounter = class(TLabel)  private     fTime : Integer;    function GetTime : Integer;    procedure SetTime(aValue : Integer);   protected  public    constructor Create(AOwner : TComponent); override;    destructor Destroy; override;   published  property Time : Integer read GetTime write SetTime;  end; procedure Register; implementation constructor TMyCounter.Create(AOwner : TComponent);begin  inherited Create(AOwner);end; destructor TMyCounter.Destroy;begin  inherited;end; function TMyCounter.GetTime : Integer;begin  Result := fTime;end; procedure TMyCounter.SetTime(aValue : Integer);begin  if fTime <> aValue then  begin      fTime := aValue;    end;end; procedure Register;begin  RegisterComponents('Misc',[TMyCounter]);end; end. ---------------------------------------------------------------------- pcurtis · 2021-11-08 18:12 Any code sample? ---------------------------------------------------------------------- pcurtis · 2021-11-08 18:22 Also is it possible to hide the caption property in the object inspector? ---------------------------------------------------------------------- wp · 2021-11-08 18:44 I do not know what exactly you want to achieve, but I guess that you want to display some elapsed time. For this I'd select the FTime variable to be a TDateTime or a TTime rather than an integer because it is very simple to create a time string from a TDateTime by using the FormatDateTime function. In order to display the time in the label's caption you should simply set the Caption in the SetTime setter procedure 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 procedure TMyCounter.SetTime(AValue: TDateTime);begin  if FTime <> aValue then  begin    FTime := aValue;    Caption := FormatDateTime(FTimeFormat, FTime);  end;end; To hide the label, set its Visible property to false. Study the attached demo. ---------------------------------------------------------------------- pcurtis · 2021-11-08 20:30 @wp It works just one thing. When I drop the component on a form it shows the component name not the time? ---------------------------------------------------------------------- wp · 2021-11-08 22:58 Did not look at the component at designtime at all because I wanted to avoid installing it... Now I installed it, and this is really a tough task, it goes deeply into the IDE form designer, and I must confess that I don't have a solution for it. Not this problem, but one thing you should do in order to be able to enter values in the Time property at designtime in time format (e.g. 12:00): - Add IDEIntf to the requirements of the package - Add propedits to the uses of the MyCounter unit (interface part) - Redeclare the FTime variable as TTime rather than TDateTime - Add the following line to the Register procedure; this adds a property editor for the Time property so that you can enter the Time in time format at designtime: 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   RegisterPropertyEditor(TypeInfo(TTime), TMyCounter, 'Time', TTimePropertyEditor); ---------------------------------------------------------------------- pcurtis · 2021-11-09 03:01 @wp This works. What do you think? 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 MyCounter; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Stdctrls, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls; type   TMyCounter = class(TCustomLabel)  private    fTime : Integer;    procedure SetTime(aValue: Integer);  protected    function RealGetText: TCaption; override;  public    constructor Create(AOwner : TComponent); override;  published    property Time: Integer read fTime write SetTime;        property Align;    property Alignment;    property Anchors;    property AutoSize;    property BidiMode;    property BorderSpacing;//    property Caption;         // we do not want to have this property any more.    property Color;    property Constraints;    property DragCursor;    property DragKind;    property DragMode;    property Enabled;    property FocusControl;    property Font;    property Layout;    property ParentBidiMode;    property ParentColor;    property ParentFont;    property ParentShowHint;    property PopupMenu;    property ShowAccelChar;    property ShowHint;  property Transparent;    property Visible;    property WordWrap;    property OnChangeBounds;    property OnClick;    property OnContextPopup;    property OnDblClick;    property OnDragDrop;    property OnDragOver;    property OnEndDrag;    property OnMouseDown;  property OnMouseEnter;    property OnMouseLeave;    property OnMouseMove;    property OnMouseUp;    property OnMouseWheel;    property OnMouseWheelDown;    property OnMouseWheelUp;    property OnMouseWheelHorz;    property OnMouseWheelLeft;    property OnMouseWheelRight;    property OnResize;    property OnStartDrag;    property OptimalFill;  end; procedure Register; implementation constructor TMyCounter.Create(AOwner : TComponent);begin  inherited Create(AOwner);end; function TMyCounter.RealGetText: TCaption;begin  inherited RealGetText;  Result := FormatDateTime('hh:mm:ss', TimeStampToDateTime(MSecsToTimeStamp(fTime * 1000)));end; procedure TMyCounter.SetTime(aValue: Integer);begin  if fTime <> aValue then  begin    fTime := aValue;  end;  Repaint;end;  procedure Register;begin  RegisterComponents('Misc',[TMyCounter]);end; end. ---------------------------------------------------------------------- wp · 2021-11-09 08:42 Good idea! ---------------------------------------------------------------------- howardpc · 2021-11-09 09:21 Minor points - you don't need to call inherited RealSetText (although unnecessary it does no harm).  Nor for this component would I think you want to publish FocusControl or WordWrap. ---------------------------------------------------------------------- pcurtis · 2021-11-09 09:34 Thanks all