Hi folks, Please find attached a patch which fixes the following issue : When we position the Kind property of a BitBtn, to "bkYes" e.g., and its parent Form is in a modal state ; clicking the button is normally supposed to close the Form and return the modal result value ("mrYes" e.g.). Here, it does not work because the ModalResult property is never positioned at design time by the SetKind() function. This patch fixes this by reorganizing function calls. To reproduce the issue, you can download the following test case [1]. Just extract it and compile it ; if you are on Windows, you can directly run "compile-delphi.bat" or "compile-lazarus.bat" (you may want edit this last script to change the %LAZPATH% variable). Notice that with Delphi, clicking on buttons gives feedback, whereas it does not with Lazarus until you apply the patch.
Regards,
Tarnyko
[1] : http://www.tarnyko.net/repo/BitBtnKind_bug.zip
From: Manuel Bachmann <tarn...@tarnyko.net>
Date: Sun, 12 Nov 2017 06:10:02 +0100
Subject: [PATCH] Fix BitBtn Kind property with ShowModal
When we position the Kind property of a BitBtn, to "bkYes" e.g.,
and its parent Form is in a modal state, it is supposed to close
the Form and return the corresponding value ("mrYes" e.g.).
It does not work because the ModalResult property is never
positioned at design time by the SetKind() function.
---
--- a/lcl/include/bitbtn.inc	2017-11-12 06:02:48.633537000 +0100
+++ b/lcl/include/bitbtn.inc	2017-11-12 06:07:38.365037671 +0100
@@ -26,7 +26,6 @@
   FButtonGlyph.OnChange := @GlyphChanged;
   FButtonGlyph.IsDesigning := csDesigning in ComponentState;
   Align := alNone;
-  RealizeKind;
 end;
 
 {------------------------------------------------------------------------------
@@ -157,8 +156,6 @@
   FKind := AValue;
   if FKind <> bkCustom then
     RealizeKind;
-  if not (csLoading in ComponentState) then
-    DefaultCaption := FKind <> bkCustom;
 end;
 
 procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout);
@@ -255,7 +252,8 @@
 
   if not (csLoading in ComponentState) then
   begin
-    Caption := GetCaptionOfKind(Kind);
+    Caption := GetCaptionOfKind(Kind);  // Will trigger TextChanged
+    DefaultCaption := Kind <> bkCustom;
     ModalResult := BitBtnModalResults[Kind];
     Default := Kind in [bkOk, bkYes];
     Cancel := Kind in [bkCancel, bkNo];
@@ -295,11 +293,7 @@
 procedure TCustomBitBtn.Loaded;
 begin
   inherited Loaded;
-  if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
-  begin
-    Caption := GetCaptionOfKind(Kind); // Will trigger TextChanged
-    DefaultCaption := True;
-  end;
+  RealizeKind;
 end;
 
 procedure TCustomBitBtn.TextChanged;
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to