View Issue Details

IDProjectCategoryView StatusLast Update
0036978LazarusLCLpublic2020-05-13 23:24
Reporterjamie philbrook Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.0.8 
Summary0036978: TComboBox needs to have the READONLY property re-enabled.
DescriptionTo my amaze after converting a rather heavily weighted app from Delphi over this laz, I find READonly has been eliminated.
 
I need to be able to set the edit field to READonly at times while the user is typing in stuff and then re-enable it later.

 I don't want to change the style in mid flight because this causes other issues that get very frustrating..

 I understand latest Delphi eliminated it but here we have Styles in the style property that Delphi does not have and I am not using a ownerdraw style for this..

 I was hoping to cross platform this app but due to who things work with this it will never happen..

currently I need to SendMessage(ComboEditHandle, EM_SETREADONLY, Ture/Flase, 0) to this fix this but that only works in windows of course.

Can we please get this fixed ?

TagsNo tags attached.
Fixed in Revisionr63110, r63112
LazTarget-
WidgetsetWin32/Win64
Attached Files

Relationships

related to 0037009 closedDmitry Boyarintsev Lazarus Lazarus fails to build on macOS after r63109 
related to 0037066 closedJuha Manninen Packages Remove unused property "ReadOnly" from CheckBox In Lr_prdlg 
related to 0037068 resolvedJuha Manninen Lazarus Current trunk does not compile carbon widget set 

Activities

Juha Manninen

2020-04-26 22:32

developer   ~0122460

A read-only ComboBox would mean that you cannot select anything from a dropdown list.
Does not make sense.

jamie philbrook

2020-04-26 23:21

reporter   ~0122466

No that's not the issue, I can still select items from the drop down, I've never had an issue with that before. its just you can not edit anything it becomes a viewable list from the edit box but not editable.
 
  The problem at times I need to lock the edit while the user is in there or at times before the user gets there because for every key stroke the OnChange event triggered and at some point there comes a need to turn the edit box into read only.
 
 This has worked flawless for years in my old Delphi package and its hardware we are talking to via serial ports and ethernet , also a GPIO port and some of the hardware isn't very well addressed for background operations so when the user is interacting with the GUI there are time we need to lock edit controls but not disable them entirely ..

 I have several controls attaching the same OnChange event which is where the data streams get piped.

Juha Manninen

2020-04-30 16:38

developer   ~0122565

Ok, now I understood the issue. TComboBox.ReadOnly has been eliminated from Delphi VCL, not from Lazarus LCL. Is it so?
To allow selecting from the dropdown list and to prevent editing you should use Style=csDropDownList. It is compatible with Delphi IIRC.
The default Style is csDropDown which allows editing.
Now I notice that ReadOnly in OI is checked automatically when you set Style=csDropDownList, and unchecked when you set Style=csDropDown.
The ReadOnly property cannot be changed directly. It is rather useless in my opinion.

Summa summarum: Does Style=csDropDownList solve your problem?

jamie philbrook

2020-04-30 22:52

reporter   ~0122566

"Summa summarum: Does Style=csDropDownList solve your problem? "

No it does not, changing the style of the box in mid flight resets the control,.


 The READONLY feature is to simply lock the current location where cursor is and when re-enabled it normally picks up where it left off, at least that is how it seems to work presenting when I use the SendMessage to enable/Disable it, you can still move the cursor around when locked, just not delete or insert any characters.

 I ported an app from DElphi, (Older version) which does have this property working and it works as expected. I have no Idea why Delphi changed it, it was a bad move on their part..

  Since there are property definitions already in the LCL implementation that Delphi currently does not have I don't see this an issue to re-enabling the API(Widget) feature that has been there since the start of time.


  if you don't want to re-enable it, it will just stop me from cross platforming it which I was hoping that maybe one day a Linux target would be doable. But the code must operate this way..

  Its possible that in other widgets this may not even work or ever worked so it still would be a dead end street for me I guess.

jamie philbrook

2020-05-01 01:24

reporter   ~0122568

Last edited: 2020-05-01 01:25

View 2 revisions

If the other widgets can't handle this I'll forget this, I just thought it was nice to have since in windows you can simple sendmessages to the control to get this , I sub classed it in Delphi but here I found the ReadOnly property there and thought that was great the other widgets supported this then found that wasn't true..
 
  I'll drop the notion of porting this to Linux because it needs to work the same way windows does when putting the EDIT control in read only mode, which is what it does and is very nice feature in windows.

 Now to figure out how to close or terminate this one..

jamie philbrook

2020-05-01 01:47

reporter   ~0122569

Sorry, It won't let me Close it...

Bart Broersma

2020-05-01 10:23

developer   ~0122574

As per reporter.
You can close now.

Juha Manninen

2020-05-01 12:30

developer   ~0122575

Let's not close yet.
TComboBox ReadOnly was deprecated in r55243 by Ondrej at 2017-06-05.
No reason is mentioned but I believe it had good reasons.
The deprecated message was updated in r59467 by Mattias at 2018-11-06.

The deprecated message says: "use extended Style values instead."
How exactly should they be used to get the old ReadOnly behavior?

Jamie Philbrook, you could have explained what had happened to this property if you already knew it?
Now I had to do some detective work to figure it out. Feels like I am doing your job.
Also the bug tracker may not be the best place. The reasons for this ReadOnly change could be asked and discussed in mailing list.

The deprecated message says the ReadOnly property will be removed in Lazarus 2.2.
I removed it and fixed the numerous side effects. The changes are in the attached patch.
There may be more side effects, I only tested with packages that happened to be installed here.
Is it OK to apply?
0001-LCL-Remove-deprecated-TComboBox.ReadOnly.patch (4,575 bytes)   
From 74ded84dd5b5d9bb6f07ea9d6c77e90fa4470c91 Mon Sep 17 00:00:00 2001
From: Juha <juha.manninen62@gmail.com>
Date: Fri, 1 May 2020 12:45:07 +0300
Subject: [PATCH] LCL: Remove deprecated TComboBox.ReadOnly.

---
 components/tachart/tachartcombos.pas  | 1 -
 components/turbopower_ipro/iphtml.pas | 1 -
 lcl/colorbox.pas                      | 1 -
 lcl/include/comboex.inc               | 2 --
 lcl/include/customcombobox.inc        | 5 -----
 lcl/stdctrls.pp                       | 4 +---
 6 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/components/tachart/tachartcombos.pas b/components/tachart/tachartcombos.pas
index 9d1265c94..9f1897e48 100644
--- a/components/tachart/tachartcombos.pas
+++ b/components/tachart/tachartcombos.pas
@@ -234,7 +234,6 @@ constructor TChartComboBox.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   DropdownCount := DEFAULT_DROPDOWN_COUNT;
-  ReadOnly := true;  // Needed to see the symbol without dropdown.
   Style := csOwnerDrawFixed;
   SetLength(FPenPattern, 2);
   FPenPattern[0] := 1;
diff --git a/components/turbopower_ipro/iphtml.pas b/components/turbopower_ipro/iphtml.pas
index fdce7771e..8ea476e72 100644
--- a/components/turbopower_ipro/iphtml.pas
+++ b/components/turbopower_ipro/iphtml.pas
@@ -12445,7 +12445,6 @@ begin
     AdjustControl;
     with TComboBox(FControl) do begin
       Style := csDropDownList;
-      ReadOnly := not FComboBox;
       OnEditingDone := ControlOnEditingdone;
     end;
   end;
diff --git a/lcl/colorbox.pas b/lcl/colorbox.pas
index 515f85b1a..f3e9044f7 100644
--- a/lcl/colorbox.pas
+++ b/lcl/colorbox.pas
@@ -381,7 +381,6 @@ constructor TCustomColorBox.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   inherited Style := csOwnerDrawFixed;
-  inherited ReadOnly := True;
 
   FColorRectWidth := -1;
   FColorRectOffset := cDefaultColorRectOffset;
diff --git a/lcl/include/comboex.inc b/lcl/include/comboex.inc
index de2af4755..f24d91366 100644
--- a/lcl/include/comboex.inc
+++ b/lcl/include/comboex.inc
@@ -275,7 +275,6 @@ begin
   FAutoCompleteOptions:=cDefAutoCompOpts;
   FItemsEx:=TComboExItems.Create(self, TComboExItem);
   FNeedMeasure:=True;
-  ReadOnly:=True;
   inherited Style:=csOwnerDrawFixed;
   FStyle:=cDefStyle;
   FStyleEx:=[];
@@ -492,7 +491,6 @@ constructor TCustomCheckCombo.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   TStringList(Items).Duplicates:=dupIgnore;
-  ReadOnly:=True;
   Style:=csOwnerDrawFixed;
   FNeedMeasure:=True;
   FRejectToggleOnSelect:=True;
diff --git a/lcl/include/customcombobox.inc b/lcl/include/customcombobox.inc
index e236923e2..649e8a52e 100644
--- a/lcl/include/customcombobox.inc
+++ b/lcl/include/customcombobox.inc
@@ -1091,11 +1091,6 @@ begin
   end;
 end;
 
-procedure TCustomComboBox.SetReadOnly(const AValue: Boolean);
-begin
-  // will be removed in 1.10
-end;
-
 {------------------------------------------------------------------------------
   procedure TCustomComboBox.UpdateSorted;
  ------------------------------------------------------------------------------}
diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp
index f00e146c1..feeda55d2 100644
--- a/lcl/stdctrls.pp
+++ b/lcl/stdctrls.pp
@@ -306,7 +306,6 @@ type
     procedure LMMeasureItem(var TheMessage: TLMMeasureItem); message LM_MeasureItem;
     procedure LMSelChange(var TheMessage); message LM_SelChange;
     procedure CNCommand(var TheMessage: TLMCommand); message CN_Command;
-    procedure SetReadOnly(const AValue: Boolean);
     procedure UpdateSorted;
     procedure SetArrowKeysTraverseList(Value: Boolean);
     procedure WMChar(var Message: TLMChar); message LM_CHAR;
@@ -404,7 +403,7 @@ type
     property DropDownCount: Integer read FDropDownCount write SetDropDownCount default 8;
     property Items: TStrings read FItems write SetItems;
     property ItemIndex: integer read GetItemIndex write SetItemIndex default -1;
-    property ReadOnly: Boolean read GetReadOnly write SetReadOnly stored False;
+    property ReadOnly: Boolean read GetReadOnly stored False;
     property SelLength: integer read GetSelLength write SetSelLength;// UTF-8 length
     property SelStart: integer read GetSelStart write SetSelStart;// UTF-8 position
     property SelText: String read GetSelText write SetSelText;
@@ -480,7 +479,6 @@ type
     property ParentFont;
     property ParentShowHint;
     property PopupMenu;
-    property ReadOnly; deprecated 'Will be removed in 2.2 - use extended Style values instead.';
     property ShowHint;
     property Sorted;
     property Style;
-- 
2.26.2

Ondrej Pokorny

2020-05-01 19:57

developer   ~0122583

Yes, the reason is that other WS do not support it and the ReadOnly name was very misleading. (Some people reported that ReadOnly should mean you cannot select anything from the drop down.)

For such scenario, I would just use a TEdit with a drop-down button next to it. Then set TEdit.ReadOnly to True.

jamie philbrook

2020-05-01 23:05

reporter   ~0122587

With ReadOnly I should be able to select anything from the drop down or even in the EDIT box..

This has and still does works in Wndows for YEARS.. many apps are built with this feature of placing the EDIT box into read only mode.

  If the behavior of which was ever any different then maybe it was never implemented correctly ?

 Placing the EDIT box into Readonly with a cdDropDown is common practice in windows, it still allows you to select any one item in the list to be put back in the EDIT box which is basically the CAPTION of the combobox..

 This feature should be done at the widget level not the LCL, a call to READONLy := ? should simply call a widget function..

 Also, when doing this it blocks the normal keystrokes from reaching the OnKeyPress Events in the control but like I said, it still allows you to scroll and select..

  Changing the style of the box in operation causes all kinds of issues, setting the readonly works perfectly as it does not change the class settings of the control.
  
  I don't know how the other widgets implement it but I would think it should be a combination of a TEDIT and TLISTBOX as it is in windows,. The same could be done there too, just put the EDIT box in read only mode..

 if you need a small demo app in windows of how it behaves and how to switch it I can supply it.

Juha Manninen

2020-05-01 23:25

developer   ~0122588

Last edited: 2020-05-01 23:27

View 2 revisions

Thanks Ondrej. I had forgotten the discussion in 2017 about this. Unfortunately Jamie cannot see it because it happened in Lazarus-devel mailing list.
I started a new mail thread in Lazarus list titled "TComboBox.ReadOnly". Please continue discussion there.
I removed the deprecated published property so it will be gone in Lazarus 2.2. A public ReadOnly property remains but is cannot be assigned any more. Thus ReadOnly property is itself readonly. :)
Please test.

For Jamie's use case a readonly TEdit with an anchored drop-down button is a good cross-platform solution.

jamie philbrook

2020-05-02 00:19

reporter   ~0122589

No, I have miles of code wrapped around this...

No thanks, I'll just stick with windows target and do it the way it should be done.

 You can close this report any time since my attempts have failed. I am done attempting to cross platform for simple matters.

 Please don't put any more afford into this on m behave, I'll just put an enhanced working version of the Tcombobox up on the palette if I choose to continue this in Lazarus.

 Thank you very much for your cooperation...

Ondrej Pokorny

2020-05-02 08:14

developer   ~0122593

Last edited: 2020-05-02 08:14

View 2 revisions

Well, the ReadOnly property in LCL was completely different from "SendMessage(ComboEditHandle, EM_SETREADONLY, Ture/Flase, 0)". It was confusing the way it was implemented in the LCL.

Delphi doesn't have the TComboBox.ReadOnly - not in the 7, XE2 nor 10.3 versions.

Issue History

Date Modified Username Field Change
2020-04-26 18:25 jamie philbrook New Issue
2020-04-26 22:32 Juha Manninen Note Added: 0122460
2020-04-26 23:21 jamie philbrook Note Added: 0122466
2020-04-30 16:38 Juha Manninen Note Added: 0122565
2020-04-30 22:52 jamie philbrook Note Added: 0122566
2020-05-01 01:24 jamie philbrook Note Added: 0122568
2020-05-01 01:25 jamie philbrook Note Edited: 0122568 View Revisions
2020-05-01 01:47 jamie philbrook Note Added: 0122569
2020-05-01 10:23 Bart Broersma Assigned To => Bart Broersma
2020-05-01 10:23 Bart Broersma Status new => resolved
2020-05-01 10:23 Bart Broersma Resolution open => no change required
2020-05-01 10:23 Bart Broersma LazTarget => -
2020-05-01 10:23 Bart Broersma Widgetset Win32/Win64 => Win32/Win64
2020-05-01 10:23 Bart Broersma Note Added: 0122574
2020-05-01 12:29 Juha Manninen Assigned To Bart Broersma => Juha Manninen
2020-05-01 12:29 Juha Manninen Status resolved => assigned
2020-05-01 12:29 Juha Manninen Resolution no change required => reopened
2020-05-01 12:30 Juha Manninen Note Added: 0122575
2020-05-01 12:30 Juha Manninen File Added: 0001-LCL-Remove-deprecated-TComboBox.ReadOnly.patch
2020-05-01 19:57 Ondrej Pokorny Note Added: 0122583
2020-05-01 23:05 jamie philbrook Note Added: 0122587
2020-05-01 23:25 Juha Manninen Status assigned => resolved
2020-05-01 23:25 Juha Manninen Resolution reopened => fixed
2020-05-01 23:25 Juha Manninen Fixed in Revision => r63110
2020-05-01 23:25 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2020-05-01 23:25 Juha Manninen Note Added: 0122588
2020-05-01 23:27 Juha Manninen Note Edited: 0122588 View Revisions
2020-05-02 00:19 jamie philbrook Note Added: 0122589
2020-05-02 08:14 Ondrej Pokorny Note Added: 0122593
2020-05-02 08:14 Ondrej Pokorny Note Edited: 0122593 View Revisions
2020-05-03 00:41 Juha Manninen Fixed in Revision r63110 => r63110, r63112
2020-05-03 00:41 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2020-05-03 10:14 Juha Manninen Relationship added related to 0037009
2020-05-13 23:17 Juha Manninen Relationship added related to 0037066
2020-05-13 23:24 Juha Manninen Relationship added related to 0037068