Like other controls, a TLabel has the flag csSetCaption included in its ControlStyle property.
This means its "default" Caption becomes its name when a label is dropped on a form.
A class helper can add a method to force a label's Caption to revert to its Name whenever you call the helper method.
For instance, drop a label and a button on the main form of a new project, and try this:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Forms, StdCtrls;
type
TLabelHelper = class helper for TLabel
public
procedure CaptionToName;
end;
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.CaptionToName;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption := 'Not your default Caption';
end;
procedure TLabelHelper.CaptionToName;
begin
Caption := Name;
end;
end.