我此刻正在使用此代码。我需要一个组合框的选定项的字符串值:无法获得ComboBox所选项目值
procedure TForm5.BitBtn5Click(Sender: TObject);
var c,k,t,g: string;
begin
//Get the name of the items
c := ComboBox1.Items[ComboBox1.ItemIndex];
k := ComboBox2.Items[ComboBox2.ItemIndex];
t := ComboBox3.Items[ComboBox3.ItemIndex];
g := ComboBox4.Items[ComboBox4.ItemIndex];
//Show it
ShowMessage(c);
end;
的组合框里面有项目,你可以看到here因为我填补他们在onCreate
事件Form5的。当我按下BitBtn5我有这样的错误:
我用Google搜索我的问题,我已经找到了代码是相同的,但我有一个错误。你有什么主意吗? (我正在使用lazarus 1.2.4)
它*更安全*(如果这是你的目标)简单地通过'ComboBox.Text'来获取这些值。 – TLama 2014-09-04 21:50:15
@TLama我没有想到它,它很简单...它的工作原理,谢谢。但我仍然不知道为什么我的代码是错误的 – 2014-09-04 21:51:52
删除'delphi'标签,因为它是误导性的。当项目索引为-1时,Lazarus引发异常,Delphi没有。 – 2014-09-04 21:53:15