This is obviously a mistake, but I can’t track why this is happening. Here is the minimalist code to play. Just clear the combo box and button in the form and write the following event handlers:
procedure TForm1.FormCreate(Sender: TObject); begin ComboBox1.Items.Add('A Item'); ComboBox1.Items.Add('B Item'); ComboBox1.Items.Add('C Item'); ComboBox1.Style := csDropDown; ComboBox1.AutoComplete := False; end; procedure TForm1.Button1Click(Sender: TObject); begin ComboBox1.Text := 'B'; ComboBox1.Font.Color := clRed; ShowMessage(IntToStr(ComboBox1.ItemIndex)); end;
When you press the button for the first time, you will see in the combined editing the fully selected text of the second element, but in the message box you will see that the index of the element is -1. When you lower it, the second element is selected. A second click will set the correct text, but the rest will be the same as the first click. Thus, the combo box in this case behaves as if some strange autocompletion was involved.
I traced this to EditWndProc , where after receiving a font change, the message WM_SETTEXT with the text of the second element, but I do not know where it came from and why with the text of the second paragraph.
So, my question is quite specific - what (which method) sends WM_SETTEXT when the font changes and how does it know about the coincidence of the text of the second element when auto-completion is disabled?
So far, I could reproduce this in Delphi 2009 and Delphi XE3 on Windows 7 Home Premium 64-bit with the latest updates installed.
source share