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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flickering DBGrid and Prior()

Status
Not open for further replies.

digimortal

Programmer
Oct 12, 2003
28
TR
void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender,
const TRect &Rect, TField *Field, TGridDrawState State)
{
Query1->Prior();
double temp = Query1value2->Value;
Query1->Next();
DBGrid1->Fields[3]->Value = Query1value1->Value + temp;
}

This is something similar to what I am trying to do, Get a value from the Previous Row and do a calculation between 2 values (One from previous row and the second one from the currenct row) and write it to a field in the current field.

The code above does the calculation write it to the field that I want but DBGrid begins flickering, jump from row to row and says something like stock overflow. Is there a better way to write this code? I think it happens because of the event I use DrawDataCell but I can not solve the problem.

Thanks in advance
 
I never use DBGrids as I find my personal StringGrid extensions better, and I prefer IBQueries (Interbase fan here), so my hint is just a wild guess, don't blame me if it's wrong :)
I think in this case problem might be with your code not checking whether Query1->Eof is false. I suppose doing Query1->Next() when Query1->Eof is true might cause some problems.

 
My line of thought was similar but with a different bent. Since this function is being called when the cell is being drawn, I was wondering if the Prior and Next were being called indefinately.

Since this function may be called whenever the cell is being drawn, it looks at the previous query, gets its value, gets the next query, gets it value, does the calulation, redraws the cell, and starts all over.

The overflow may be caused by Query1value1->Value + temp forever adding the values until the value overflows its maximum size (or memory allocation).

James P. Cottingham
-----------------------------------------
To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top