在delphi中,可以添加具有不同大小写的组合框项(在我的示例大写中)。`
ComboBox1.Items.Add('SYDNEY');
ComboBox1.Items.Add('MOSCOW');
ComboBox1.Items.Add('BERLIN');
ComboBox1.Items.Add('BERN');
ComboBox1.Items.Add('PARIS');`

但是,在尝试搜索时,组合框文本与项目大小写类型不同。
并将以“BERLIN”而不是“柏林”的形式插入数据库。
UniQuery1.SQL.Add('INSERT INTO login (id,user) values (10,'''+ComboBox1.text+''')');是否有方法自动将文本更改为实际项目情况?
发布于 2019-12-22 11:33:56
在您的示例中,所有的城市名称都是大写的。因此,您确实可以按照注释中的建议使用UpperCase()函数。
但是,更普遍的解决方案是检查if ItemIndex <> -1,指出确实选中了一个项,然后使用Items[ItemIndex]来存储在db中,而不是Text属性。
评论后编辑:
要更新Text属性和选择,请尝试如下:
procedure TForm20.ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
ss, sl: integer;
SelectedItemString: string;
begin
with ComboBox1 do
begin
ss := SelStart;
sl := SelLength;
if ItemIndex <> -1 then
SelectedItemString := Items[ItemIndex]
else
SelectedItemString := Text;
Text := SelectedItemString;
SelStart := ss;
SelLength := sl;
end;
Key := 0;
end;https://stackoverflow.com/questions/59443104
复制相似问题