浏览代码

TLabel.SetName set Caption

mattias 2 年之前
父节点
当前提交
ca6bb9ef7e
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      src/fresnel.controls.pas

+ 14 - 0
src/fresnel.controls.pas

@@ -72,6 +72,7 @@ type
     FSize: TFresnelPoint; // width+height of Caption
     FSize: TFresnelPoint; // width+height of Caption
     procedure ComputeMinCaption; virtual;
     procedure ComputeMinCaption; virtual;
     procedure SetCaption(const AValue: String); virtual;
     procedure SetCaption(const AValue: String); virtual;
+    procedure SetName(const NewName: TComponentName); override;
   public
   public
     function GetMinWidthIntrinsicContentBox: TFresnelLength; override;
     function GetMinWidthIntrinsicContentBox: TFresnelLength; override;
     function GetPreferredContentBox_MaxWidth(MaxWidth: TFresnelLength): TFresnelPoint;
     function GetPreferredContentBox_MaxWidth(MaxWidth: TFresnelLength): TFresnelPoint;
@@ -335,6 +336,19 @@ begin
   DomChanged;
   DomChanged;
 end;
 end;
 
 
+procedure TCustomLabel.SetName(const NewName: TComponentName);
+var
+  ChangeCaption: Boolean;
+begin
+  if Name=NewName then exit;
+  ChangeCaption :=
+    not (csLoading in ComponentState)
+    and (Name = Caption)
+    and ((Owner = nil) or not (csLoading in Owner.ComponentState));
+  inherited SetName(NewName);
+  if ChangeCaption then Caption := NewName;
+end;
+
 function TCustomLabel.GetMinWidthIntrinsicContentBox: TFresnelLength;
 function TCustomLabel.GetMinWidthIntrinsicContentBox: TFresnelLength;
 var
 var
   p: TFresnelPoint;
   p: TFresnelPoint;