Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TStringGrid causes program termination

Status
Not open for further replies.

MoonchildHK

Programmer
Jun 5, 2001
22
HK
Hi All,

I am using a TStringGrid in a progra, with one fixed row and no fixed columns. When I write to the 3nd row of the grid, the program unexpectly terminates? I can't figure out any reason.. no errors, no exxceptions, nothing. Just quits!
I have ensured there are enough rows to write to, and it worked for a while, then it suddenly stopped working!

Here is the code I am using to write to the grid:
(Where sgRequests is the StringGrid, lRequests is a TList, and tempRequest is a structure I defined myself)

Code:
sgRequests->RowCount = lRequests->Count+1;

sgRequests->Cells[4][lRequests->Count] = IntToStr(tempRequest->memberID);
sgRequests->Cells[3][lRequests->Count] = tempRequest->memberName;
sgRequests->Cells[2][lRequests->Count] = IntToStr(tempRequest->girlID);
sgRequests->Cells[1][lRequests->Count] = tempRequest->girlName;
sgRequests->Cells[0][lRequests->Count] = IntToStr(tempRequest->id);

tempRequest->girlID, memberID and id are INT types;
tempRequest->girlName and memberName are CHAR * types;

Any help or ideas would be much appreciated.

Thanks,

 
have you stepped through the code? place a break at the beginning of the code, and walk through it. then when you find the line that causes the crash, remove it and find another way of doing the same function that that line does.

you may be running out of memory, that is often a reason programs crash. check to make sure there isn't a memory leak. and if your running Windows NT, try keeping the system monitor up and check to see how much memory is being used when your program runs.
if your not using NT and you want a system monitor to check this, e-mail me at hackcyprus@hotmail.com and I'll send you one for a non-NT system. Cyprus
 
Yes, I did use the debuger to check which line was causing the termination. It was always the first line that writes a string to any cell on the 3rd row of the StringGrid (I have 1 fixed row at the top). I have plenty of memory spare at the time too. I can't figure it out!

Moonchild
 
A couple of things that may or may not be the cause.
Code:
String ATempInt = 0;
try
{
    ATempInt = IntToStr(tempRequest->memberID);
}
catch (...)
{
    // if IntToStr doesn't work put error code here
}

String ATempChar = tempRequest->memberName.c_str(); // worth a shot

sgRequests->Cells[4][lRequests->Count] = ATempInt;
sgRequests->Cells[3][lRequests->Count] = ATempChar;
// repeat for other cells
.
.
.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top