View Issue Details

IDProjectCategoryView StatusLast Update
0015731LazarusLCLpublic2011-12-01 11:23
ReporterPaul van HeldenAssigned ToPaul Ishenin 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.28.3 (SVN)Product Build 
Target Version1.0.0Fixed in Version0.9.29 (SVN) 
Summary0015731: Ampersands (&) not handled properly in labels
DescriptionWhen you actually want to see an ampersand (without repeating it) you have the option to set ShowAccelChar:=False. The label resizes incorrectly though, showing that the textwidth function is not called with the necessary flag to show single ampersands. The fix should be trivial, but...
Additional InformationRequest: I think that showing "accelerator characters" by default is idiotic. I know it is Windows default behaviour in functions like DrawText. You cannot assume that all labels on a form might be containing an accelerator char, so I would like the default of ShowAccelChar to be false at least.

My labels are often populated from a database so this problem only surfaces in the rare occasion that a string contains an &.

Suggestion: without a FocusControl set, the behaviour of a label might as well be as if ShowAccelChar=False since the programmer obviously isn't using that feature. The simplest solution would be to not have the ShowAccelChar property at all and show the label as if it was true only when FocusControl<>nil.
TagsNo tags attached.
Fixed in Revision24944
LazTarget1.0
WidgetsetWin32/Win64, WinCE
Attached Files
  • customlabel.accelchar_fix.diff (459 bytes)
    Index: customlabel.inc
    ===================================================================
    --- customlabel.inc	(revision 24483)
    +++ customlabel.inc	(working copy)
    @@ -48,6 +48,9 @@
         if not HasMultiLine then
           Flags := Flags or DT_SINGLELINE;
     
    +    if not ShowAccelChar then
    +      Flags := Flags or DT_NOPREFIX;
    +
         LabelText := GetLabelText;
         DrawText(DC, PChar(LabelText), Length(LabelText), R, Flags);
         SelectObject(DC, OldFont);
    

Activities

Dimitri Smits

2010-03-13 02:29

reporter   ~0035421

this is the standard value as in D7.
illogical as it may seem, that is default behaviour. Moreover, setting ShowAccelChar := false, triggers that FocusControl will not be used!

from the D7 VCL help:

Delphi syntax:
property ShowAccelChar: Boolean;

C++ syntax:
__property bool ShowAccelChar = {read=FShowAccelChar, write=SetShowAccelChar, default=1};

Description

Set ShowAccelChar to true to allow the label to display an underlined accelerator key value. When ShowAccelChar is true, any character preceded by an ampersand (&) appears underlined. If the FocusControl property is set, the windowed control specified by the FocusControl property receives input focus when the user types that underlined character. To display an ampersand when ShowAccelChar is true, use two ampersands (&&) to stand for the single ampersand that is displayed.

Set ShowAccelChar to false to display the label text with all ampersands appearing as ampersands. When ShowAccelChar is false, the value of the FocusControl property is not used.

2010-04-25 13:52

 

customlabel.accelchar_fix.diff (459 bytes)
Index: customlabel.inc
===================================================================
--- customlabel.inc	(revision 24483)
+++ customlabel.inc	(working copy)
@@ -48,6 +48,9 @@
     if not HasMultiLine then
       Flags := Flags or DT_SINGLELINE;
 
+    if not ShowAccelChar then
+      Flags := Flags or DT_NOPREFIX;
+
     LabelText := GetLabelText;
     DrawText(DC, PChar(LabelText), Length(LabelText), R, Flags);
     SelectObject(DC, OldFont);

Bart Broersma

2010-04-25 13:58

developer   ~0036995

Proposed patch (in customlabel.accelchar_fix.diff) seems to fix this (wrong autosizing with ShowAccelChar = false) for me for TLabel (on Win32 at least).

Does this affect other controls as well?

Paul Ishenin

2010-04-26 04:46

manager   ~0037003

Please test and close if ok.

Issue History

Date Modified Username Field Change
2010-02-10 13:57 Paul van Helden New Issue
2010-02-10 13:57 Paul van Helden Widgetset => Win32/Win64, WinCE
2010-03-12 11:11 Vincent Snijders LazTarget => 1.0
2010-03-12 11:11 Vincent Snijders Status new => acknowledged
2010-03-12 11:11 Vincent Snijders Target Version => 1.0.0
2010-03-13 02:29 Dimitri Smits Note Added: 0035421
2010-04-25 13:52 Bart Broersma File Added: customlabel.accelchar_fix.diff
2010-04-25 13:58 Bart Broersma Note Added: 0036995
2010-04-26 04:46 Paul Ishenin Fixed in Revision => 24944
2010-04-26 04:46 Paul Ishenin Status acknowledged => resolved
2010-04-26 04:46 Paul Ishenin Fixed in Version => 0.9.29 (SVN)
2010-04-26 04:46 Paul Ishenin Resolution open => fixed
2010-04-26 04:46 Paul Ishenin Assigned To => Paul Ishenin
2010-04-26 04:46 Paul Ishenin Note Added: 0037003
2011-12-01 11:23 Marc Weustink Status resolved => closed