[SOLVED] problems with HourGlass-Cursor over a TStringGrid lazarus / 31-LCL ---------------------------------------------------------------------- Hartmut · 2016-10-07 15:19 I have a TStringGrid and want to compute and show one row after each other. Because this needs some time for > 1000 rows, I will show the HourGlass-Cursor until the last row is done. But in my program this works only, if the mouse is over the StringGrid area at the moment, when I press the button (by TAB and ENTER). When I press the button with the mouse (so the mouse is not over the StringGrid area at this moment) I don't get the HourGlass-Cursor, even if I move the mouse now over the StringGrid area. I'm working on Windows 7 32 bit. Can please somebody tell me, what I do wrong? I zipped and appended my example project, if someone wants to compile and start it. Code: [Select]procedure TForm1.Button1Click(Sender: TObject);    var n: integer;    begin    Stringgrid1.RowCount:=1;  {1 row for the titles}    Stringgrid1.FixedCols:=0; {no fixed colums}    Stringgrid1.ColCount:=1;  {have only 1 column}    Stringgrid1.Cells[0,0]:='Results';    Stringgrid1.Cursor:=crHourGlass; {want HourGlass-Cursor}    for n:=1 to 10 do       begin       Stringgrid1.RowCount:=n+1;  {add 1 row}       sleep(300);                 {compute something...}       Stringgrid1.Cells[0,n]:='Hello' + intToStr(n);       StringGrid1.Refresh;        {show the new line}       end;    StringGrid1.Cursor:=crDefault; {back to normal Cursor}    end; ---------------------------------------------------------------------- molly · 2016-10-07 15:40 Try screen.Cursor. ---------------------------------------------------------------------- wp · 2016-10-07 15:41 Quote from: Hartmut on October 07, 2016, 05:19:43 pmI have a TStringGrid and want to compute and show one row after each other. Because this needs some time for > 1000 rows (...)Why? 1000 lines add within the wink of an eye. Did you call StringGrid1.BeginUpdate before you add the cells? This will avoid the repainting operations. Afterwards you must call StringGrid1.EndUpdate in order to activate painting again. Quote from: Hartmut on October 07, 2016, 05:19:43 pmBut in my program this works only, if the mouse is over the StringGrid area at the moment, when I press the button (by TAB and ENTER). When I press the button with the mouse (so the mouse is not over the StringGrid area at this moment) I don't get the HourGlass-Cursor, even if I move the mouse now over the StringGrid area. Use the Cursor of the Screen to avoid the button presses. Here is my modification of your code. Note the try-finally block to make sure that the grid's EndUpdate is called and the Screen.Cursor is reset if an exception occurs: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var   n: integer;begin  Stringgrid1.RowCount:=1;  {1 row for the titles}  Stringgrid1.FixedCols:=0; {no fixed colums}  Stringgrid1.ColCount:=1;  {have only 1 column}  Stringgrid1.Cells[0,0]:='Results';  Screen.Cursor := crHourGlass;  StringGrid1.BeginUpdate;  try    for n:=1 to 1000 do    begin      Stringgrid1.RowCount:=n+1;  {add 1 row}  // <-- having this outside the loop (StringGrid1.RowCount := 1001) would be faster!//      sleep(300);                 {compute something...}      Stringgrid1.Cells[0,n]:='Hello' + intToStr(n);    StringGrid1.Refresh;        {show the new line}    end;  finally    Screen.Cursor := crDefault;    StringGrid1.EndUpdate;  end;end; (And I gave your code a more conventional indentation - I never understand why so many people use their own indentation rules. Proper indentation is the key to see missing end statements and illegal blocks immediately). ---------------------------------------------------------------------- Thaddy · 2016-10-07 15:44 @wp You mean, start with Python and THEN switch to Object Pascal? I fully agree about indentation. ---------------------------------------------------------------------- Hartmut · 2016-10-07 16:14 To use Screen.Cursor() instead of Stringgrid1.Cursor() works perfect :-) BeginUpdate() and EndUpdate() I did not know, but now. Thanks a lot again to wp for your help.