【发布时间】:2012-05-30 06:17:09
【问题描述】:
我正在开发一个应用程序,其中我有一个带有长文本值的组合框。由于文本值很大(以字符为 ..20 或更多),要显示在组合框中,要求显示在first 从下拉列表中选择后的字符。
就像在红色标记的图像中一样。如果用户选择第 3 项 3 0.5 to 1.25 Slight 我应该只在组合框中显示 3。
所以我尝试了这个
sTheSelectedValue : string;
procedure TForm1.ComboBox1Select(Sender: TObject);
begin
sTheSelectedValue:=TrimTextAndDisplay(ComboBox1.Text); //send theselected value
ComboBox1.Text :=''; //clear the selection
ComboBox1.Text:=sTheSelectedValue; //now assign as text to combo box
Button1.Caption:=ComboBox1.Text; //just show the new value on the button.
end;
function TForm1.TrimTextAndDisplay(TheText : string): string;
var
sTheResult : string;
begin
sTheResult :=copy(TheText,0,1); //extract the first value..
Result :=sTheResult;
end;
结果是
按钮似乎显示了正确的值,但没有显示组合框。
我想要的是在组合框中获得3,我似乎无法设置ComboBox1.Text:=
谁能告诉我该怎么做?
像这样从组合框中选择结果应该是
【问题讨论】: