Recent

Author Topic: TStringGrid refresh  (Read 14337 times)

GAlex

  • New Member
  • *
  • Posts: 13
TStringGrid refresh
« on: December 26, 2004, 01:26:18 pm »
:?: Why the TStringGrid component does not refresh in runtime?

To better explain, let me say that when the application modify the content of the cells using the cells[] property in response to a keypress or another event (edit option disabled), and then change the position of the cursor by using the "row" and "col" properties, the control does not update the cursor position (the dotted red square), leaving the first cell selected (in negative gfx) together with garbage drawing (dotted lines, selected cells, and so on...).

It doesn't redraw itself even after a gridname.refresh() call; only by clicking with the mouse on the grid, the control redraws and cleans the bad graph remains.

Any advice :?:  :?:  :?:

jesusr

  • Sr. Member
  • ****
  • Posts: 482
Re: TStringGrid refresh
« Reply #1 on: December 27, 2004, 10:14:38 am »
Quote from: "GAlex"
:?: Why the TStringGrid component does not refresh in runtime?

To better explain, let me say that when the application modify the content of the cells using the cells[] property in response to a keypress or another event (edit option disabled), and then change the position of the cursor by using the "row" and "col" properties, the control does not update the cursor position (the dotted red square), leaving the first cell selected (in negative gfx) together with garbage drawing (dotted lines, selected cells, and so on...).

It doesn't redraw itself even after a gridname.refresh() call; only by clicking with the mouse on the grid, the control redraws and cleans the bad graph remains.

Any advice :?:  :?:  :?:


Tried to reproduce without success after two tests.
test 1) drop a TStringgrid in a form, make a keypress event and write this code:
Code: [Select]

  Grid.Cells[Grid.Col,Grid.Row]:=Key;
  Grid.Col := Grid.Col+1;

test 2) drop a TStringgrid and a TEdit, make a TEdit OnChange and TEdit KeyDown, in OnChange I Write:
Code: [Select]

  Grid.Cells[Grid.Col,Grid.Row]:=Edit1.Text

in KeyDown I write:
Code: [Select]

  if Key=VK_RETURN then
    Grid.Col := Grid.Col + 1;


I think this test follow your description, however both test work fine in windows and with a recent lazarus version. Can you give more details, code, screenshots, anything to help to reproduce the problem so it gets fixed, thanks.

GAlex

  • New Member
  • *
  • Posts: 13
TStringGrid refresh
« Reply #2 on: December 27, 2004, 06:11:27 pm »
:arrow: Here You are, as requested; the dev platform currently is win32, Lazarus version is of 10th dec 2004 (the latest I presume); I've not yet tested this code in Linux-GTK;
(commented code portions follows):

Code: [Select]

procedure TCruci.thegridKeyPress(Sender: TObject; var Key: char);
var
  x: LongInt;
  y: LongInt;
  c: char;
begin
     if key in ['a'..'z', 'A'..'Z'] then begin
          c:=upcase(key);
          x:=thegrid.col;
          y:=thegrid.row;
          if thegrid.cells[x,y] = '' then begin
             thegrid.cells[x,y]:=c;

Here the char is inserted in the appropriate cell on the grid, and the cell gfx switch to selected (negative) ...
Code: [Select]

... (if conditionals)
                repeat begin
                            if x < 14 then thegrid.col+=1
                            else thegrid.col:=0
                       end
                until (thegrid.cells[thegrid.col,y] = '') or (thegrid.col <> x);
... (else conditional)

... and here the cursor (red dotted square) is not updated on the grid during the loop, nor at the end, and the cell[x,y] (i.e. the first cell that originates the event) is always in selected gfx ...
Code: [Select]

... (previous conditionals)
     else if key = chr(08) then begin  // the backspace key (I know use of chr(ascii-code) it's deprecated, and I should use defined constants VK_*, but I'm only in an early debug stage and that will be fixed  :? )

                if thegrid.col>0 then thegrid.col-=1
                else thegrid.col:=15;
                if thegrid.cells[thegrid.col, thegrid.row]<>'' then begin
                   thegrid.cells[thegrid.col, thegrid.row]:='';
                   p1p-=1;
                end

... this leaves the grid cursor (the red dotted square) drawed in the cell that generated the event ...
Code: [Select]

     thegrid.refresh()
end;

... this is the end of the procedure, but the .refresh() call does not seem to work.
I'm unable to post a screenshot (I don't know how to insert an image in this post), but seems that losing focus (the form) clears the bad red squares, leaving the "selected" cells in negative gfx ...

I've looked for the TStringGrid control source code, but found nothing wrong :!:

Thanks in advance for anyone who knows how to fix.
[/img]

jesusr

  • Sr. Member
  • ****
  • Posts: 482
TStringGrid refresh
« Reply #3 on: December 27, 2004, 07:15:57 pm »
Quote from: "GAlex"
:arrow: Here You are, as requested; the dev platform currently is win32, Lazarus version is of 10th dec 2004 (the latest I presume); I've not yet tested this code in Linux-GTK;
(commented code portions follows):

Code: [Select]

....snip....
                repeat begin
                            if x < 14 then thegrid.col+=1
                            else thegrid.col:=0
.... snip .....
                if thegrid.col>0 then thegrid.col-=1
                else thegrid.col:=15;
                if thegrid.cells[thegrid.col, thegrid.row]<>'' then begin
                   thegrid.cells[thegrid.col, thegrid.row]:='';
                   p1p-=1;
                end

... this leaves the grid cursor (the red dotted square) drawed in the cell that generated the event ...
Code: [Select]

     thegrid.refresh()
end;

... this is the end of the procedure, but the .refresh() call does not seem to work.
I'm unable to post a screenshot (I don't know how to insert an image in this post), but seems that losing focus (the form) clears the bad red squares, leaving the "selected" cells in negative gfx ...

I've looked for the TStringGrid control source code, but found nothing wrong :!:

Thanks in advance for anyone who knows how to fix.
[/img]


The problem is the use of the operators +=, -= in properties that have methods as does Grid.Col, the method Grid.SetCol is never called. The operators seems to access the properties directly and so, the grid's mechanism to refresh and update internal values is not triggered.

Try to replace all expressions that use +=,-= operators with normal pascal expressions: Grid.Col := Grid.Col + 1; and Grid.Col := Grid.Col - 1;

GAlex

  • New Member
  • *
  • Posts: 13
TStringGrid refresh
« Reply #4 on: December 27, 2004, 08:36:56 pm »
:D It works :!:
Now I should do 2 things:

1. stop using C-like construct and assignments while writing programs in Pascal :cry: ;

2. stop using this nasty emoticons :twisted: arghhh :evil: in my posts.

Thanks alot.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2552
TStringGrid refresh
« Reply #5 on: December 28, 2004, 03:42:29 pm »
Maybe you should also file a bug on fpc. IMO, modifying properties with += should not be allowed.
It is the same as Inc(Grid.Col, 1), that is also not allowed (AFAIK)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

jesusr

  • Sr. Member
  • ****
  • Posts: 482
TStringGrid refresh
« Reply #6 on: December 28, 2004, 07:14:42 pm »
done: bug id=3488, I had chosen a better description, though.

 

TinyPortal © 2005-2018