Jump to content
alogrep

Stringgrid cell value changed arbitrarely

Recommended Posts

HI.

I have lost 21 hours on this,.

 

I have a stringrid that I need to make a function work correcly. 

I store a value of Zero in all cells[13,row].

I pass the grid to another function, and right at the beginning of this function misteriousely that value is changed to '1';

This is the code

 

begin
linesdone:='';       // SO FAR IT IS OK, STILL '0'
   prnums:=Tstringlist.create;
   with dm2  do  begin
      stationprinters.indexname:='number';
      stationprinters.setrange([_mycompname,1],[_mycompname,123]) ;
      stationprinters.first;
      while not stationprinters.eof  do begin
        prnums.add(stationprinters.fieldbyname('printernumber').asstring);
        stationprinters.next;
      end;
      stationprinters.cancelrange;
    end;
chekqtys;  // AS SOON S IT GETS HERE THE VALUE IS '1';

The even strangerthis is that if I comment out the  

prnums.add(stationprinters.fieldbyname('printernumber').asstring);

the value stays to '0'. But then I cannot use the rest of the function, b/c I need the count and the printerindex that

need to be used. The stationprinters table has no relation to the stringgrid whatsoever.

Anybody has any hint,clue,suggestion,guessing or anything that can help me avoid going crazy?

Share this post


Link to post

Very difficult to understand your question..

You talk about a stringgrid but in the code you posted the grid isn't mentioned.

You talk about a value? What value? All the valueS (more values) in the rows of the grid?

Share this post


Link to post

OK maybe it wasn't clear.

The grid is not shown in the code because is unrelated to that peace of code;

A more completa  chunk of code:

procedure printorder(grid: Tstringgrid);
begin
linesdone:='';       // SO FAR IT IS OK, STILL '0'
   prnums:=Tstringlist.create;
   with dm2  do  begin
      stationprinters.indexname:='number';
      stationprinters.setrange([_mycompname,1],[_mycompname,123]) ;
      stationprinters.first;
      while not stationprinters.eof  do begin
        prnums.add(stationprinters.fieldbyname('printernumber').asstring);
        stationprinters.next;
      end;
      stationprinters.cancelrange;
    end;
chekqtys; // this is a procedure;
.....
....
compactgrid()

And inside checkqtys() I manipulate the grid.

 I do not know why but the problem seems to have disappeared. Just as I do not know why it appeared.

Maybe b/c deep inside checkqtys() I had a line where I set the cells[13,row to '1'. (but on certain conditions)

But why WAY BEFORE it reached that point the value of the grid was changed?

 

 

 

Share this post


Link to post

Try to get rid of the "with dm2 do begin". It might not cause the issue but makes codereading and debugging significantly more difficult (debugger evaluator usually goes nuts).

I had strange text in DBGrids some time ago, it was caused by memory corruption in the DB access component. Based on what you posted, there's no mentions of the stringgrid so I tend to think your issue might be caused by something like this too.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×