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:
procedure TForm1.SpeedButtonTestClick (Sender: TObject);
begin
ComboBox1.Clear;
ComboBox1.Items.Add('TestItem0');
ComboBox1.Items.Add('TestItem1');
ComboBox1.Items.Add('TestItem2');
ComboBox1.Text:='Test'
if ComboBox1.Font.Color<>clRed then
ComboBox1.Font.Color:=clRed
else
ComboBox1.Font.Color:=clDefault;
with ComboBox1 do
begin
SendDebugFmt('ComboBox1.Text=%s; .ItemIndex=%d; .SelText=%s; -',
[Text,ItemIndex,SelText]);
SendDebugFmt('ComboBox1.AutoComplete=%s; .AutoSelected=%s',
[BoolToStr(AutoComplete,true),BoolToStr(AutoSelected,true)]);
end;
end;
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