如何获取ComboBox项目数

Pow*_*fet 1 c++ vcl c++builder

我正在尝试使用以下代码获取组合框项目数.它不会给出错误,也不会给出正确的计数.我想我必须将int转换为字符串,但是如何?

ComboBox1->ItemIndex = 1;
int count = ComboBox1->Items->Count;
Edit1->Text =  "Count: " + count;
Run Code Online (Sandbox Code Playgroud)

mat*_*975 5

这条线

 int count = ComboBox1->Items->Count; 
Run Code Online (Sandbox Code Playgroud)

返回TComboBox中字符串项的numnber.您需要在设置前进行检查

ComboBox1->ItemIndex = 1;
Run Code Online (Sandbox Code Playgroud)

作为ItemIndex用于在组合框中设置所选项目并且为零计数.要在Embarcadero中将整数转换为字符串,您可以使用IntToStr()函数

Edit1->Text = "Count:" + IntToStr(count)
Run Code Online (Sandbox Code Playgroud)

您将需要#include "System.hpp"访问该功能