How to save the Normal Size of the Form to the configuration file lazarus / 31-LCL ---------------------------------------------------------------------- tomitomy · 2017-10-28 03:10 Hi, everyone, I want to save the Normal Size of the Form to the configuration file when exiting the program, but if the Form is Maximized when you exit the program, you will not save the Normal Size, but the Maximized Size, Does anyone know how to deal with this situation? ---------------------------------------------------------------------- PatBayford · 2017-10-28 04:00 Well, one obvious way would be to have a pair of properties to store the normal size. ---------------------------------------------------------------------- tomitomy · 2017-10-28 05:16 Quote from: PatBayford on October 28, 2017, 06:00:16 amWell, one obvious way would be to have a pair of properties to store the normal size. Thank you, PatBayford. But I don't know how to get the Normal Size when the Form Maximizing. Test Code: 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 var  NormalRect: TRect; procedure SaveFormSize(Rect: TRect);begin  writeln(Format('Form Size Saved: %d, %d, %d, %d', [NormalRect.Left, NormalRect.Top, NormalRect.Width, NormalRect.Height]));end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  if WindowState = wsNormal then    NormalRect := BoundsRect;  SaveFormSize(NormalRect);end; procedure TForm1.FormWindowStateChange(Sender: TObject);begin  if WindowState <> wsNormal then begin    NormalRect := BoundsRect;  // How to get Normal Size  end;end; ---------------------------------------------------------------------- jamie · 2017-10-29 00:38 restoreLeft, restoreTop, RestoreWidth and RestoreHeight These are part of the form  I do not know why they didn't simply return a BoundsRect or simply a Trect here ? ---------------------------------------------------------------------- tomitomy · 2017-10-29 02:14 Quote from: jamie on October 29, 2017, 02:38:02 amrestoreLeft, restoreTop, RestoreWidth and RestoreHeight These are part of the form  I do not know why they didn't simply return a BoundsRect or simply a Trect here ? I'm sorry, I didn't know the attributes like "restoreLeft" before. Thank you for helping me! ---------------------------------------------------------------------- tomitomy · 2017-10-30 02:21 Hi, I have tried "restoredLeft, restoredTop, restoredWidth, restoredHeight", but it doesn't work, Is there anything wrong with my usage? Test Code: 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.FormWindowStateChange(Sender: TObject);begin  writeln(WindowState, ' : ',    Format('%d, %d, %d, %d',    [restoredLeft, restoredTop,    restoredWidth, restoredHeight]));end; ---------------------------------------------------------------------- engkin · 2017-10-30 04:50 Quote from: tomitomy on October 30, 2017, 03:21:44 amHi, I have tried "restoredLeft, restoredTop, restoredWidth, restoredHeight", but it doesn't work, Is there anything wrong with my usage? Test Code: 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.FormWindowStateChange(Sender: TObject);begin  writeln(WindowState, ' : ',    Format('%d, %d, %d, %d',    [restoredLeft, restoredTop,    restoredWidth, restoredHeight]));end; Your usage seems ok and it works fine here on Windows. The GIF shows that both RestoredTop and RestoredLeft hold right values. I doubt it, but maybe you need to be outside the event. Try something like: 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   TForm1 = class(TForm)    ...    procedure StateChanged(AData:PtrInt); ... procedure TForm1.FormWindowStateChange(Sender: TObject);begin  Application.QueueAsyncCall(@StateChanged, 0);end; procedure TForm1.StateChanged(AData: PtrInt);begin  writeln(WindowState, ' : ',    Format('%d, %d, %d, %d',    [restoredLeft, restoredTop,    restoredWidth, restoredHeight]));end; ---------------------------------------------------------------------- tomitomy · 2017-10-30 06:40 Quote from: engkin on October 30, 2017, 05:50:40 amI doubt it, but maybe you need to be outside the event. Try something like: Thank you, engkin, My OS is Linux Mint MATE, I tried your code, but the result was the same. I also tested the code in Win7 virtual machine, everything is fine. It looks like a BUG. ---------------------------------------------------------------------- engkin · 2017-10-31 00:01 Quote from: tomitomy on October 30, 2017, 07:40:43 amI tried your code, but the result was the same. It is not the same. Your second GIF shows that you get wrong values when the form is maximized. Quote from: tomitomy on October 30, 2017, 07:40:43 amIt looks like a BUG. I agree. ---------------------------------------------------------------------- jamie · 2017-10-31 00:23 I just did a test on 1.6.4 64 bits windows. They do work however, I noticed they are late on defining their values.  for example, If I implement the OnSize event for the Tform, the first OnSize event trigger shows that theses values are all zero. But they are defined after the OnSize event, meaning, if I Maximize the form that same OnSize event will get called again and the values are now assigned.  And if I size the form to see that it has enlarged 1 pixel for example, then do the Maximize again, I can see that it actually sized two pixels but because these values are getting updated after the Onsize event makes it hard to track accurate sizes if you are dragging the form size around. procedure TForm1.FormResize(Sender: TObject); begin   Caption := RestoredLeft.ToString+','+RestoredTop.ToString+','+Restor edWidth.ToString+','+RestoredHeight.ToString; end; Try this.  Initial OnSize shows 0,0,0,0; Then do something like maximize and you'll see that they now show the restore values. then Drag the form size so something different, you'll see they are changing but then do a maximize and you'll see the values will to a slightly different value.. This proves it is doing late settings after the OnSize event. ---------------------------------------------------------------------- tomitomy · 2017-10-31 01:40 Thank you engkin and jamie. I have submitted the issue to the bug tracker forum: https://bugs.freepascal.org/view.php?id=32631