resizing StringGrid in Win10 lazarus / 34-Windows ---------------------------------------------------------------------- rick2691 · 2016-12-30 14:07 The following is a code excerpt from a much larger application. I can only hope that I have included all of its critical elements for your review. This code is for resizing the row heights and column widths when the main form has been dragged or otherwise resized. It works well in WinXP, but Win10 will not modify the row and column sizes, no errors are reported. Win10 will, however, resize the columns if I manually drag them. Can anyone tell me what to do to make it work in Win10? 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 unit CmdDatCode;  {$mode objfpc}{$H+}    interface uses Grids; type TMainFrm = class(TForm)                       PostPts: TStringGrid;                                            private                          procedure FormatGrid;                       end;              var ApplyResize: double;     // to apply Scaling to Grid Columns     MaxP: integer;     // practical maximum for PostPts.RowCount value implementation {$R *.lfm}  procedure TmainFrm.FormatGrid; {Populate PostPts Tabbed Point List}var  PstPnt,Str1: string;  z: integer;begin  PostPts.ColCount:= 5;  PostPts.DefaultRowHeight:= trunc(22*ApplyResize);   if MaxP>9999 then MaxP:=9999;  if MaxP<10000 then PostPts.RowCount:= MaxP+1 //was MaxP+1;   {data}                else PostPts.RowCount:= MaxP;    PostPts.colwidths[0]:= trunc(60*ApplyResize);   {point}  PostPts.colwidths[1]:= trunc(128*ApplyResize);   {north}  PostPts.colwidths[2]:= trunc(128*ApplyResize);   {east}  PostPts.colwidths[3]:= trunc(90*ApplyResize);   {height}  PostPts.colwidths[4]:= trunc(224*ApplyResize);  {description}   PostPts.Cells[0, 0]:= ' Point';     {titles}  PostPts.Cells[1, 0]:= ' Northing';  PostPts.Cells[2, 0]:= ' Easting';  PostPts.Cells[3, 0]:= ' Height';  PostPts.Cells[4, 0]:= ' Description';   for z:= 1 to MaxP do      begin      if z<10000 then         begin         Str(z, PstPnt);       PostPts.Cells[0, z]:= ' '+PstPnt;  {list points}         end;      end;end;  end.  Rick ---------------------------------------------------------------------- derek.john.evans · 2016-12-30 15:37 I dont know, but this is what I'd check. Are you running Laz v1.4.4? If so, test with 1.6.2+ Are you testing the same exe, or are you recompiling on the Win10 machine? Both are 32bit? To me it sounds like a missing resize event. If so, try manually calling the resize event via the TStringGrid resize event (or TForm onresize) ---------------------------------------------------------------------- tk · 2016-12-30 15:59 Quick thoughts: Where is ApplyResize set (and is it set correctly under Win10)? Should not it be better an input parameter for FormatGrid? What about some minimalistic example project first (one form, one grid etc)? Does it work? ---------------------------------------------------------------------- rick2691 · 2016-12-30 17:36 Yes, I am using Laz 1.4.4, and I am compiling in WinXP and applying compatibility in Win10. I am not using any event. I am resizing by code, and then assigning the scale factor to ApplyResize (0.85 thru 1.45). I don't use Laz 1.6.2 because it has made problems in both WinXP and Win10. The FormatGrid is called by the FormActivate event. Since I don't use an event I can't see why the columns and Row heights can't be changed in Win10. I have assumed that it is an internal function that shouldn't have anything to do with Win10, since everything else functions properly. I have about a dozen applications that worked fine. This is the only one that uses Tstrings. I have also compiled it in Win10 (with both Laz 1.4.4 and 1.6.2, and it had the same problem with both of them. Since this is my first attempt to work with Win10, and I am still learning about compatibility and permissions, I am going to repeat the process. I am also going to try setting the call to FormatGrid before the actual resizing of the form... but again, WinXP handles it fine as it is. Rick ---------------------------------------------------------------------- rick2691 · 2016-12-30 18:34 I relocated the call to FormatGrid to where it preceded the Form resizing, and it had no effect. I compiled the app in Win10 with fpc 1.4.4, and it could not compile it. I compiled in Win10 with fpc 1.6.2 @ 64 bit, and it could not compile it. I compiled in Win10 with fpc 1.6.2 @ 32 bit, and it did compile, but had no effect on resizing the Tstring grid. I am assuming that it is a Tstring bug... unless there is a conditional parameter that has to be set for Win10. Perhaps something that is similar to: {$IFDEF FPC}   {$MODE Delphi} {$ENDIF} Rick ---------------------------------------------------------------------- rick2691 · 2016-12-31 14:18 I have found a conditional windows code from another thread... {$IFDEF WINDOWS}   uses win32proc; {$ENDIF} // ... {$IFDEF WINDOWS}   if WindowsVersion >= wv10 then      Showmessage('OS is Windows 10 or later'); {$ENDIF} If you think that this is the right approach, and if any of you can help me on deducing what should be added to the wv10 portion I would be most grateful. Rick ---------------------------------------------------------------------- tk · 2016-12-31 16:53 Did you also try recent trunks (Lazarus + FPC, you can comfortably setup them with fpcupdeluxe now)? I don't see any such problems in Win10, tried now with some older demo project comparing StringGrid vs. KGrid (I only use KGrid now). So I am pretty sure the cause is somewhere else, not in the StringGrid component. Without complete project, hard to say what is the problem. ---------------------------------------------------------------------- wp · 2016-12-31 18:15 I can't give specific advice because you don't show enough code. But here's how I would do a stringgrid which resizes column widths and row heights and font size along with the size of the grid. And it works perfectly in Win10, Win 7 and Win2000, with Laz trunk and Laz 1.4.0. Did you provide a handler for the grid's OnResize? ---------------------------------------------------------------------- rick2691 · 2016-12-31 20:17 wp, Thanks for your example. I will look in to it. But trust me, that is all of the resizing code for stringgrid. I resize the from with uScaleDPI, but it cannot adjust the stringgrid, so I take its scaling factor and apply it to stringgrid with FormatGrid. Nothing else happens. I will look into your example. Rick ---------------------------------------------------------------------- rick2691 · 2016-12-31 20:46 I tested your project in Win10. It performed without a fault. The only immediate difference that I can notice is that you are resizing in runtime and dynamically. I am doing a one-time resize at FormActivate, and that I am doing custom widths for each column. I am sure that a closer examination will reveal where my flaw is... it just befuddles me at this point is that it works in WinXP. Rick ---------------------------------------------------------------------- rick2691 · 2017-01-01 21:14 WP, I tried to translate your code into my own, and again it worked in XP and not 10. So I decided to ditch my code, and then adjust yours to my needs... it worked in both perfectly.  I still can't see why, unless it is your use of "FOrigColWidths, FOrigRowHeights: Array of Integer;" I think that it is all that I had tried to omit when translating to my own code. But the bottom line is... I am happy to have gotten past it all. There is one tweak that I added... multiplying "factor" by 1.012. It's only an approximate adjustment, but it helps with the vertical scroll bar not being scaled. It stays the same size, and of course, that isn't applicable to your application (only mine). Much thanks, Rick ---------------------------------------------------------------------- wp · 2017-01-01 21:42 If I understand you correctly you want to scale the grid along with the screen resolution? In this case you should give Lazarus trunk a try. Recently, form scaling has been completely rewritten - see http:/ /wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_Lazarus_1.7_and_abov e. I know that you are still using version 1.4.4, but with fpcupdeluxe you can easily install any Lazarus version without interfering with your primary install (seek for fpcupdeluxe here in the forum). ---------------------------------------------------------------------- rick2691 · 2017-01-02 16:03 Thanks for the information. I will give 1.7 a try. It looks like it has some good features. I have stayed with 1.4 because it is solid. 1.6 has given me troubles... mostly just small annoyances, but in Win10 (I had tried it because I thought it was designed for it) it hadn't been able to compile anything until I installed the 32 bit version. My issues with form size have not been on account of DPI problems. My software was built with a 1024x820 screen. The forms were too big on smaller screens, so I made them as small as was workable for the larger. Now I have even larger screens to deal with (1920x1024) and all the forms are too tiny (yet it uses 96 DPI). So using the uScaleDPI unit has resolved the problem. I just contrive a smaller base DPI and it expands all of the forms, but it could'nt expand the String Grid. Your code has resolved the issue. With it I provide a percentage scale for shrinking or expanding the forms (85% to 145% in 5% increments). It allows the user deal with screen sizes for both large and small screen situations. I was able to adapt your code to the same method. Happy New Year to you. Thanks again for the assistance. Rick ---------------------------------------------------------------------- rick2691 · 2017-01-03 14:13 QuoteThere is one tweak that I added... multiplying "factor" by 1.012. It's only an approximate adjustment, but it helps with the vertical scroll bar not being scaled. It stays the same size, and of course, that isn't applicable to your application (only mine). For those who wonder where I came up with the above multiplier, I had taken a ruler and scaled the form as it appears on the screen. As such, it is only useful with my current system configuration. An exact method (that also incorporates the system parameters) would be as follows: factor:= (PostPts.Width - VertScrollbar.Size) / (FOrigWidth - VertScrollbar.Size); The above is only applicable when a vertical scroll bar is present in all conditions. Rick ---------------------------------------------------------------------- rick2691 · 2017-01-04 13:57 I am posting the following because I found a different behavior between WinXP and Win10 for dealing with vertical scroll bars. WinXP needs the scroll bar width to be handled by the code. Win10 internally compensates for the scroll bar. The code below reports the active Windows version and uses different methods. I also found that if you are using compatibility to WinXP, it reports that Windows XP is your operating system, but it still compensates for the scroll bar itself. So your own handling of the scroll bar is counter productive. I removed compatibility, and everything operated properly. 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 TMainFrm.GridOnCreate(Sender: TObject);    // called by FormCreatevar  i,j: Integer;begin  PostPts.RowCount:= 101;  PostPts.ColCount:= 6;  PostPts.colwidths[0]:= 60;   {point}  PostPts.colwidths[1]:= 128;   {north}  PostPts.colwidths[2]:= 128;   {east}  PostPts.colwidths[3]:= 90;   {grade}  PostPts.colwidths[4]:= 220;  {text}   for i:=0 to PostPts.ColCount-1 do      begin      // alternatively to... PostPts.Cells[i, 0]:= 'Col'+IntToStr(i);      // with the below the title cells are posted, and the cell data is populated later      case i of           0: PostPts.Cells[i,0]:= ' Point';           1: PostPts.Cells[i,0]:= ' North';           2: PostPts.Cells[i,0]:= ' East';           3: PostPts.Cells[i,0]:= ' Grade';           4: PostPts.Cells[i,0]:= ' Text';           end;      for j:=1 to PostPts.RowCount-1 do          PostPts.Cells[i,j] := ' ';      end;   FOrigWidth:= PostPts.Width;  //FOrigFontHeight := GetFontData(PostPts.Font.Handle).Height;   // handled by ScaleDPI in FormActivate  SetLength(FOrigColWidths, PostPts.ColCount);  SetLength(FOrigRowHeights, PostPts.RowCount);   for i:= 0 to High(FOrigColWidths) do      FOrigColWidths[i]:= PostPts.ColWidths[i];  for i:= 0 to High(FOrigRowHeights) do      FOrigRowHeights[i]:= PostPts.RowHeights[i];end; procedure TMainFrm.GridOnActivate(Sender: TObject);   // called by FormActivatevar  factor: Double;  i: Integer;  s: string;begin  {$IFDEF WINDOWS}  if WindowsVersion = wvLater   // Win10   // uses win32proc ... wvXP wvVista wv7 wv8 wvLater     then begin          factor:= PostPts.Width / FOrigWidth;          //str(VertScrollbar.Size,s);          //showmessage('Win10 bar='+s);        end;  if WindowsVersion = wv8       // Win8    // uses win32proc ... wvXP wvVista wv7 wv8 wvLater     then begin          factor:= PostPts.Width / FOrigWidth;          //str(VertScrollbar.Size,s);          //showmessage('Win8 bar='+s);        end;  if WindowsVersion = wv7       // Win7    // uses win32proc ... wvXP wvVista wv7 wv8 wvLater     then begin          factor:= PostPts.Width / FOrigWidth;          //showmessage('Win7');          end;  if WindowsVersion = wvVista   // Vista   // uses win32proc ... wvXP wvVista wv7 wv8 wvLater     then begin          factor:= PostPts.Width / FOrigWidth;          //showmessage('WinVista');        end;  if WindowsVersion = wvXP      // WinXP   // uses win32proc ... wvXP wvVista wv7 wv8 wvLater     then begin          factor:= (PostPts.Width - VertScrollbar.Size) / (FOrigWidth - VertScrollbar.Size);          //str(VertScrollbar.Size,s);          //showmessage('WinXP bar='+s);          end;  {$ELSE}  begin  factor:= (PostPts.Width - VertScrollbar.Size) / (FOrigWidth - VertScrollbar.Size);  //showmessage('Other');  end;  {$ENDIF}   for i:= 0 to PostPts.ColCount-1 do      PostPts.ColWidths[i]:= round(factor * FOrigColWidths[i]);   for i:= 0 to PostPts.RowCount-1 do      PostPts.RowHeights[i]:= round(factor * FOrigRowHeights[i]);   //PostPts.Font.Height := round(factor * FOrigFontHeight);   // handled by ScaleDPI in FormActivateend; Rick