0

Hello everybody i have C++ tStringGrid

I want to get string from specific cell with coordinates

I have tried this but without luck:

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

Error:

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

Please help.

manlio
  • 18,345
  • 14
  • 76
  • 126
user525717
  • 1,612
  • 5
  • 28
  • 40
  • Do you know how big the grid is? ie: is 3,2 out of bounds? – Zac Jul 01 '12 at 21:46
  • @Zac: the address it is reading is a NULL pointer. Likely the cell referenced is uninitialized. – user7116 Jul 01 '12 at 21:50
  • @user525717: Can you show us what ColCount and RowCount are at runtime? Perhaps Objects[3,2] is null, or show us more about StringGrid1 (which may be NULL as well). – user7116 Jul 01 '12 at 21:50
  • Do you mean this objects? >>> Form1->StringGrid1->Cells[1][i] = name.c_str(); Form1->StringGrid1->Cells[2][i] = address.c_str(); – user525717 Jul 01 '12 at 21:53

1 Answers1

3

I don't have a working dev enviroment up that can build this but try:

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

It might be an AnsiString instead of a UnicodeString.

Zac
  • 3,235
  • 4
  • 25
  • 30
  • Also StringGrid1 could be null. – user7116 Jul 01 '12 at 21:53
  • its a good idea to put the assert in there too - just to check your codes assumptions. Could also include `StringGrid1 != nullptr` from @sixlettervariables in the assert. – Zac Jul 01 '12 at 22:07