Recent

Author Topic: TComboBox behaves strange on changing TComboBox.Font.Color  (Read 2789 times)

RolfW

  • New Member
  • *
  • Posts: 21
TComboBox behaves strange on changing TComboBox.Font.Color
« on: February 07, 2018, 12:57:24 pm »
Hi,
I want to change the ComboBox.Font.Color in the ComboBox.OnChanged event procedure depending on the ComboBox.Text. This doesn't work as ComboBox.Text switches to ComboBox.Items[0] text. Here is a demo code to show what happens:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButtonTestClick (Sender: TObject);
  2. begin
  3.   ComboBox1.Clear;
  4.   ComboBox1.Items.Add('TestItem0');
  5.   ComboBox1.Items.Add('TestItem1');
  6.   ComboBox1.Items.Add('TestItem2');
  7.  
  8.   ComboBox1.Text:='Test'
  9.   if ComboBox1.Font.Color<>clRed then
  10.     ComboBox1.Font.Color:=clRed
  11.   else
  12.     ComboBox1.Font.Color:=clDefault;
  13.  
  14.   with ComboBox1 do
  15.   begin
  16.     SendDebugFmt('ComboBox1.Text=%s; .ItemIndex=%d; .SelText=%s; -',
  17.                  [Text,ItemIndex,SelText]);
  18.     SendDebugFmt('ComboBox1.AutoComplete=%s; .AutoSelected=%s',
  19.                  [BoolToStr(AutoComplete,true),BoolToStr(AutoSelected,true)]);
  20.   end;
  21. end;
  22.  

And this is the DebugServer result:
Identify: [12:53:07] Process project1
Information: [12:53:07] ComboBox1.Text=TestItem0; .ItemIndex=-1; .SelText=TestItem0; -
Information: [12:53:07] ComboBox1.AutoComplete=False; .AutoSelected=False

So, changing .Font.Color changes the ComboBox.Text from 'Test' to 'TestItem0';

Thanks,
Rolf

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: TComboBox behaves strange on changing TComboBox.Font.Color
« Reply #1 on: February 07, 2018, 01:53:55 pm »
Looks like a bug. But it's an old one: even Lazarus 1.0 has the same behavior. And Delphi XE 10.2 Tokyo, too.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TComboBox behaves strange on changing TComboBox.Font.Color
« Reply #2 on: February 08, 2018, 02:19:59 am »
That maybe following the standard windows combobox, at least the listbox part of it.

 setting the text depends on where the cursor is within the box if you do this from a windows
point of view

 Its been a while but I am sure setting the text depends on the condition of the SelStart selLength  and SelText
etc..

 If you dig down deeper, the SetTextBuf is suppose to replace all of the list box etc.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018