看起来您Text
在OnSelect
活动期间所做的更改随后会被框架覆盖。无论是 Windows API 还是 VCL,我都没有调查过哪个。
一种解决方案是将实际更改推迟到原始输入事件的处理完成为止。像这样:
const
WM_COMBOSELECTIONCHANGED = WM_USER;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure ComboBox1Select(Sender: TObject);
protected
procedure WMComboSelectionChanged(var Msg: TMessage); message WM_COMBOSELECTIONCHANGED;
end;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1Select(Sender: TObject);
begin
PostMessage(Handle, WM_COMBOSELECTIONCHANGED, 0, 0);
end;
procedure TForm1.WMComboSelectionChanged(var Msg: TMessage);
begin
if ComboBox1.ItemIndex<>-1 then
begin
ComboBox1.Text := Copy(ComboBox1.Text, 1, 1);
ComboBox1.SelectAll;
end;
end;