【问题标题】:C++ builder TstringGrid get string from specific cellC++ builder TstringGrid 从特定单元格获取字符串
【发布时间】:2012-07-01 21:30:50
【问题描述】:

大家好,我有 C++ tStringGrid

我想从具有坐标的特定单元格中获取字符串

我试过了,但没有运气:

UnicodeString cell_obj = StringGrid1->Objects[3][2]->ToString();

错误:

Access violation at address 00407617 in module 'NGG_Client.exe'. Read of address 00000000.

请帮忙。

【问题讨论】:

  • 你知道网格有多大吗? ie: 3,2 是否越界?
  • 是的,我知道它是固定的......
  • @Zac:它正在读取的地址是一个 NULL 指针。可能引用的单元格未初始化。
  • @user525717:你能告诉我们运行时 ColCount 和 RowCount 是什么吗?也许 Objects[3,2] 为空,或者向我们展示更多关于 StringGrid1 的信息(也可能为 NULL)。
  • 你的意思是这个对象吗? >>> Form1->StringGrid1->Cells[1][i] = name.c_str(); Form1->StringGrid1->Cells[2][i] = address.c_str();

标签: c++ c++builder vcl tstringgrid


【解决方案1】:

我没有可以构建它的工作开发环境,但请尝试:

assert( StringGrid1->ColCount > 3 && StringGrid1->RowCount > 2 );
UnicodeString cell_str = StringGrid1->Cells[3][2];

它可能是AnsiString 而不是UnicodeString

【讨论】:

  • StringGrid1 也可以为空。
  • 把断言也放在那里是个好主意——只是为了检查你的代码假设。还可以在断言中包含来自@sixlettervariables 的StringGrid1 != nullptr
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多