ComboBox.Sorted发生了什么事:= True;在Delphi 10.2中? [英] What has happened to ComboBox.Sorted := True; in Delphi 10.2?
问题描述
最近我收到最后一个问题的风滚草徽章,我不确定是否应该再问其他问题,但这是可行的。
Having recently received a 'Tumbleweed' badge for my last question, I am not sure whether I should be asking any more questions, but here goes.
我是使用sqlite表中的项目填充 TComboBox
,效果很好。在我以前的Delphi版本中,我可以使用 ComboBox1.Sorted:= True;
对项目进行排序,但是在Delphi 10.2中似乎消失了。我可以通过应用查询对表中的项目进行排序,然后从已排序的表中填充 TComboBox
。但是,出于好奇,我想了解一下现在如何对 TComboBox
中的项目进行排序。我已经找到了对 TComboBox(Sort:Compare)
的引用,但是到目前为止还没有成功使它生效。
I am populating a TComboBox
with items from a sqlite table and this works fine. In my previous version of Delphi I was able to use ComboBox1.Sorted := True;
to sort the items, but this seems to have disappeared in Delphi 10.2. I can sort the items in the table by applying a query and then populate the TComboBox
from the sorted table. However, for curiosities sake I would like to find out how one now sorts items in a TComboBox
. I have found some references to TComboBox(Sort:Compare)
but have not succeeded in getting this to work to as of yet.
有人可以对此进行说明吗?-谢谢
Can somebody please shed some light on this - many thanks
推荐答案
在Firemonkey中,您可以填充 TComboBox
实例,只需使用 TStrings
类型的 Items
属性,或添加 TListBoxItem
实例与表单设计器。但是内部总是使用 TListBoxItem
作为元素。
In Firemonkey you can populate a TComboBox
instance either simply with the Items
property of type TStrings
or you add TListBoxItem
instances with the form designer. But internally always TListBoxItem
for the elements is used.
要使用 TComboBox.Sort
您需要提供一个匿名比较功能。
To use the TComboBox.Sort
you need to provide an anonymous compare-function.
这是 TComboBox.Sort的简单用法示例
cbxItems.Sort(
function (pLeft, pRight: TFMXObject): Integer
var
lLeft, lRight: TListBoxItem;
begin
lLeft := TListBoxItem(pLeft);
lRight := TListBoxItem(pRight);
Result := String.Compare(lLeft.Text, lRight.Text);
end
);
这篇关于ComboBox.Sorted发生了什么事:= True;在Delphi 10.2中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!