Recent

Author Topic: cannot set Readonly to true in TComboBox in object inspector.  (Read 173 times)

sergioantonio2013

  • New Member
  • *
  • Posts: 21
cannot set Readonly to true in TComboBox in object inspector.
« on: September 15, 2019, 09:03:49 pm »
I dont know if this is normal, when I add a TComboBox, and when I try to set the Readonly to true in the object inspector, it does not let me set it to true.

I want to have a drop down list of options, but I do not want the user to type in an option, I just want them to select it from  the drop-down list. I assume this is done by setting the Readonly field to true, which I can not seem to be able to do.

Any help on how I can get this to work. I'm using Lazarus 2.0.4
« Last Edit: September 15, 2019, 09:18:42 pm by sergioantonio2013 »

wp

  • Hero Member
  • *****
  • Posts: 6225
Re: cannot set Readonly to true in TComboBox in object inspector.
« Reply #1 on: September 15, 2019, 09:33:13 pm »
In the combobox sources I find for the setter of the ReadOnly property
Code: Pascal  [Select]
  1. procedure TCustomComboBox.SetReadOnly(const AValue: Boolean);
  2. begin
  3.   // will be removed in 1.10
  4. end;
This means that it is no longer possible to set ReadOnly to true in this direct way. This is probably due to historical and compatibility reasons.

Then, how to make the combobox such that only items can be selected from the dropdown? The getter of the property is
Code: Pascal  [Select]
  1. function TCustomComboBox.GetReadOnly: Boolean;
  2. begin
  3.   Result := Style in [csDropDownList, csOwnerDrawFixed, csOwnerDrawVariable];
  4. end;
  5.  
This means that when the combobox Style is one of these options the combobox becomes readonly. Set Style to csDropDownList, and you'll notice that the ReadOnly property automatically becomes checked.

« Last Edit: September 15, 2019, 09:35:36 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

sergioantonio2013

  • New Member
  • *
  • Posts: 21
Re: cannot set Readonly to true in TComboBox in object inspector.
« Reply #2 on: September 15, 2019, 09:34:32 pm »
never mind, I just set the style to csDropDownList, and got the effect I wanted.

I'm not sure what the readonly field is for, if it does not work.

ASerge

  • Hero Member
  • *****
  • Posts: 1405
Re: cannot set Readonly to true in TComboBox in object inspector.
« Reply #3 on: September 15, 2019, 09:36:42 pm »
In the combobox sources I find for the setter of the ReadOnly property
Code: Pascal  [Select]
  1. procedure TCustomComboBox.SetReadOnly(const AValue: Boolean);
  2. begin
  3.   // will be removed in 1.10
  4. end;
In TCombobox:
Code: Pascal  [Select]
  1. property ReadOnly; deprecated 'Will be removed in 2.2 - use extended Style values instead.';
If ReadOnly used in source code, the compiler issues this warning.