Formsize component fails to re-apply and anchor

I am having a problem with the formsize component on Windows 10 build 1709 and 1607 with Delphi Tokyo 10.2.2 and component pack 8.8.5.0. In the simplest case I place a panel at the top left of a window, with all four anchors set, and a button below and to the right of this, with only bottom/right anchors. I am not sure yet whether the problem started to happen after upgrading TMS, Windows 10, or Delphi.


Adding a formsize component has the following effect when you run the program.  If you pull the window to a larger width and height, and close it, then when you next run the program the window size is restored by FormSize but the panel size and button position remain as designed.  So when you manually reduce the window to its earlier size , the panel size is reduced (destroying its content, in a real program) and the button moves to where the panel was.

If I remove the formsize component and simply add a "width := 1500;" in a FormShow method, both the form and the panel are sized larger as expected on re-opening and the button remains in the bottom right corner of the form, all as specified by the anchors.

I see you have added an undocumented UseHook property in the latest release, but setting this to either value makes no difference.  If there is a simple fix I can apply to FormSize it would be preferable to having to change the 80 forms where we use this.

I have retested this here on Windows 10, Delphi Tokyo and I cannot see a problem. The panel & button position are resized according to the last form size that was persisted in the INI file.
Form file with which this was retested:


object Form4: TForm4
  Left = 0
  Top = 0
  Caption = 'Form4'
  ClientHeight = 461
  ClientWidth = 852
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  DesignSize = (
    852
    461)
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 8
    Top = 8
    Width = 836
    Height = 65
    Anchors = [akLeft, akTop, akRight, akBottom]
    Caption = 'Panel1'
    TabOrder = 0
  end
  object Button1: TButton
    Left = 769
    Top = 79
    Width = 75
    Height = 25
    Anchors = [akRight, akBottom]
    Caption = 'Button1'
    TabOrder = 1
  end
  object FormSize1: TFormSize
    MagnetDistance = 32
    SaveUser = False
    SaveMachine = False
    SaveName = '.\FORM.INI'
    SaveKey = 'Form4'
    Version = '1.4.1.3'
    Left = 424
    Top = 240
  end
end

Hi,

the problem sounds fimilar ...
Try to set The Form-Option "Position" to "poDefaultPosOnly".
Maybe this helps.

Greetings from germany
 Peter Nomden

Default is poDefaultPosOnly  and we cannot see an issue with poDefaultPosOnly.
I tried several other settings for Position and also could not see an issue with restoring the form size & position via TFormSize.

The problem may be related to the fact that I am developing on a machine at 120dpi.  When I save a form this value is automatically set in PixelsPerInch. This 10.2.2 Delphi release is the first one I have found where 'it just works' (on other resolution screens) when I do this, and I have never been able to work on two 1920x1200 screens using only 96dpi, so I have used non-scaled forms (in Delphi Berlin and earlier) up to now.  I did not mention this in my original posting because I thought I had tested a build developed on a 96dpi machine with the same result, but I cannot now be sure about this.


Nevertheless I have just found a solution to my problem.  I have gone back to an old version of Formsize.pas from about 3 years ago, before the 'hook' code was added, and extracted the relevant bits (some of which are still present, commented out) into the method of the current source that sets the screen dimensions.  Now I have no panels squashed down when I reduce the window size set by the component.

Thanks for the suggestions, and apologies if I missed a relevant fact.