无法获得ComboBox所选项目的值 [英] Cannot get ComboBox selected item value

查看:107
本文介绍了无法获得ComboBox所选项目的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此代码.我需要获取ComboBox所选项目的String值:

I am using this code at the moment. I need to get the String value of the selected item of a 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;

组合框内部有项目,您可以在此处看到,因为我在onCreate事件中填充了它们表格5.当我按下BitBtn5时,我出现了这样的错误:

The ComboBoxes have items inside as you can see here because I fill them in an onCreate event of the Form5. When I press the BitBtn5 I have an error like this:

我用Google搜索了我的问题,发现代码是相同的,但是我遇到了这个错误.你有什么主意吗? (我正在使用lazarus 1.2.4)

I have googled my problem and I have found the code is the same, but I have that error. Do you have any idea? (I am using lazarus 1.2.4)

推荐答案

您的ComboBox的物品索引中至少有一个是-1.在创建时将它们设置为有效索引,例如:

At least one of your ComboBox's item index is -1. Set them to a valid index at form creatiton, eg:

ComboBox1.ItemIndex := 0;

这篇关于无法获得ComboBox所选项目的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆