View Issue Details

IDProjectCategoryView StatusLast Update
0037472LazarusLCLpublic2020-08-04 22:10
ReporterJoeny Ang Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.1 (SVN) 
Summary0037472: [Patch] TBitBtn: DefaultCaption not resetting Caption
DescriptionFor Kind <> bkCustom, setting DefaultCaption to True should reset Caption to default value.
Steps To Reproducevia ObjectInspector:
- drop a TBitBtn to a form
- set Kind to bkOk
- modify Caption to something
- check DefaultCaption

via Code:
- see test project
TagsNo tags attached.
Fixed in Revisionr63692
LazTarget-
Widgetset
Attached Files

Activities

Joeny Ang

2020-08-03 07:23

reporter  

tbitbtn-defaultcaption-not-resetting-caption.patch (2,328 bytes)   
--- lcl/buttons.pp.63676
+++ lcl/buttons.pp
@@ -174,6 +174,7 @@
     procedure SetNumGlyphs(AValue: Integer);
     procedure SetSpacing(AValue: Integer);
     procedure RealizeKind(ForceDefaults: Boolean);
+    procedure SetDefaultCaption(const AValue: Boolean);
     //Return the caption associated with the aKind value.
     function GetCaptionOfKind(AKind: TBitBtnKind): String;
     function GetImages: TCustomImageList;
@@ -205,7 +206,7 @@
     function CanShowGlyph(const AWithShowMode: Boolean = False): Boolean;
   public
     property Caption stored IsCaptionStored;
-    property DefaultCaption: Boolean read FDefaultCaption write FDefaultCaption default False;
+    property DefaultCaption: Boolean read FDefaultCaption write SetDefaultCaption default False;
     property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
     property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
     property Images: TCustomImageList read GetImages write SetImages;
--- lcl/include/bitbtn.inc.63676
+++ lcl/include/bitbtn.inc
@@ -230,7 +230,7 @@
   if (FKind <> bkCustom) and not (csLoading in ComponentState) then
     RealizeKind(True);
   if not (csLoading in ComponentState) then
-    DefaultCaption := FKind <> bkCustom;
+    FDefaultCaption := FKind <> bkCustom;
 end;
 
 procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout);
@@ -348,6 +348,17 @@
   end;
 end;
 
+procedure TCustomBitBtn.SetDefaultCaption(const AValue: Boolean);
+begin
+  if FDefaultCaption = AValue then Exit;
+  FDefaultCaption := AValue;
+  if (Kind <> bkCustom) and DefaultCaption then
+  begin
+    Caption := GetCaptionOfKind(FKind); // will trigger TextChanged
+    FDefaultCaption := True;
+  end;
+end;
+
 { Return the caption associated with the akind value.
   This function replaces BitBtnCaption const because the localizing
   do not work with an const array }
@@ -386,7 +397,7 @@
   if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
   begin
     Caption := GetCaptionOfKind(Kind); // Will trigger TextChanged
-    DefaultCaption := True;
+    FDefaultCaption := True;
   end;
 end;
 
@@ -394,7 +405,7 @@
 begin
   inherited TextChanged;
   AdjustSize;
-  DefaultCaption := False;
+  FDefaultCaption := False;
 end;
 
 class function TCustomBitBtn.GetControlClassDefaultSize: TSize;

Juha Manninen

2020-08-04 22:10

developer   ~0124569

Looks reasonable. Applied, thanks.

Issue History

Date Modified Username Field Change
2020-08-03 07:23 Joeny Ang New Issue
2020-08-03 07:23 Joeny Ang File Added: tbitbtn-defaultcaption-not-resetting-caption.patch
2020-08-03 07:23 Joeny Ang File Added: tbitbtn-defaultcaption-not-resetting-caption-test01.zip
2020-08-04 22:09 Juha Manninen Assigned To => Juha Manninen
2020-08-04 22:09 Juha Manninen Status new => assigned
2020-08-04 22:10 Juha Manninen Status assigned => resolved
2020-08-04 22:10 Juha Manninen Resolution open => fixed
2020-08-04 22:10 Juha Manninen Fixed in Revision => r63692
2020-08-04 22:10 Juha Manninen LazTarget => -
2020-08-04 22:10 Juha Manninen Note Added: 0124569