Recent

Author Topic: [SOLVED] How to query the outer size of a 'TForm' ?  (Read 5960 times)

dsiders

  • Hero Member
  • *****
  • Posts: 1472
Re: How to query the outer size of a 'TForm' ?
« Reply #30 on: October 15, 2024, 12:41:29 am »
It's even in the FAQ.
::)

BTW. I expected this piece of crucial information to be in the normal docs, where there is no mention of it. Especially because it's different behavior from Delphi.

Fair enough.

I have topics updates that's are pending for 4.0. Let me review what it would take to apply them for 3.8.

I have an update ready that changes ClientHeight, ClientWidth, Height and Width. For example:

Code: Text  [Select][+][-]
  1. TControl.ClientHeight
  2. The height for the client area on the control.
  3.  
  4. ClientHeight is an Integer property with the number of pixels needed for vertical
  5. client area on the control. The property contains the value from the Bottom
  6. member in ClientRect. Changing the value for ClientHeight causes SetClientSize
  7. to be called to apply the existing ClientWidth and the new value for the property.
  8.  
  9. The value for ClientHeight is not stored or used to set the Height for the control
  10. during LCL component streaming. It is used, however, when AutoSizing is restored
  11. and when auto-layout policies using Anchors are applied to the control. For example,
  12. when Anchors is set to [akBottom] the value in ClientHeight is needed / used.
  13.  
  14. In the LCL, ClientHeight has the same value as Height. Derived classes (like
  15. TCustomForm or TForm) may implement a ClientHeight property that differs from Height -
  16. but in the current LCL version, they do not. This differs from the behavior in the Delphi
  17. VCL where a TForm instance adjusts the value in ClientHeight to remove pixels used in
  18. non-client areas like the title bar, borders, frames, and scroll bars. LCL uses this approach
  19. because there is no reliable way to determine the sizes for all of the non-client areas on all
  20. of the platforms where LCL is supported. Without a reliable way, the LCL would needlessly
  21. move the forms around on the screen or resize them endlessly. In the LCL, neither Height
  22. nor ClientHeight include the non-client area on a form instance. The height of a TMainMenu
  23. instance is omitted from both values as well.
  24.  
  25. Use ClientWidth to access the number of pixels needed for the horizontal client area on the control.
  26.  
  27. See Also
  28.     TControl.ClientRect
  29.     TControl.ClientWidth
  30.     TControl.Height
  31.     TControl.AutoSizing
  32.     TControl.EnableAutoSizing
  33.     TControl.AutoAdjustLayout
  34.     TControl.Resize
  35.     TControl.Anchors

I plan to apply it to both fixes_3_0 (for the release in 3.8) and in fixes_4.

Feedback appreciated.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Hartmut

  • Hero Member
  • *****
  • Posts: 1007
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #31 on: October 15, 2024, 10:55:11 am »
Feedback appreciated.

Thank you very much dsiders for your continuous and valuable work on the documentation. I'm not familar with all aspects you have written (like AutoSizing or Anchors) but from what I understand it is a good and very helpful text.

MaartenJB

  • Full Member
  • ***
  • Posts: 119
Re: How to query the outer size of a 'TForm' ?
« Reply #32 on: July 06, 2025, 02:15:43 pm »
I plan to apply it to both fixes_3_0 (for the release in 3.8) and in fixes_4.

Feedback appreciated.

Hi, I don't seem to get it to work properly, and cannot get a constant form height, even using the ClientHeight. I've just put a tmainmenu(added an entry) on the form and tmemo (no align).
See attachment images, first is after application start and the second is when I move the form. (a move shouldn't even trigger a resize, but I was trying to work around that by comparing the previous height/width)

Code: Pascal  [Select][+][-]
  1. var
  2.   ResizeCount : Integer;
  3. procedure TForm1.FormResize(Sender: TObject);
  4. begin
  5.   Inc(ResizeCount,1);
  6.   Memo1.Lines.Add(Format('Height: %d (Count: %d)', [ClientHeight, ResizeCount]));
  7. end;
  8.  
  9. procedure TForm1.FormCreate(Sender: TObject);
  10. begin
  11.   Memo1.Lines.Text := 'Actieve LCL widgetset: ' + WidgetSetClass.ClassName + LineEnding + LineEnding;
  12. end;
  13.  

Lazarus 3.6 (rev lazarus_3_6) FPC 3.2.2 x86_64-linux-gtk2 (Debian12/cinnamon)
« Last Edit: July 06, 2025, 04:45:32 pm by MaartenJB »

MaartenJB

  • Full Member
  • ***
  • Posts: 119
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #33 on: July 06, 2025, 09:39:10 pm »
Ah, just found out that it works fine with lazarus version 2.2.6, even the onresize triggers at the right moment. Seems like something broke in 3.0 and later versions.

Works: Lazarus 2.2.6 (rev lazarus_2_2_6)  FPC 3.2.2 x86_64-linux-gtk2
Doesnt work: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 x86_64-linux-gtk2

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #34 on: July 07, 2025, 09:33:28 am »
Ah, just found out that it works fine with lazarus version 2.2.6, even the onresize triggers at the right moment. Seems like something broke in 3.0 and later versions.

Works: Lazarus 2.2.6 (rev lazarus_2_2_6)  FPC 3.2.2 x86_64-linux-gtk2
Doesnt work: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 x86_64-linux-gtk2
Did you try Lazarus 4?
With an older trunk version from december, this doesn't happen.

MaartenJB

  • Full Member
  • ***
  • Posts: 119
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #35 on: July 07, 2025, 10:05:08 am »
Ah, just found out that it works fine with lazarus version 2.2.6, even the onresize triggers at the right moment. Seems like something broke in 3.0 and later versions.

Works: Lazarus 2.2.6 (rev lazarus_2_2_6)  FPC 3.2.2 x86_64-linux-gtk2
Doesnt work: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 x86_64-linux-gtk2
Did you try Lazarus 4?
With an older trunk version from december, this doesn't happen.

Hi, It's the same problem, I've just tried both:

Lazarus 4.99 (rev main_4_99-2249-g07f6d4dbe2) FPC 3.2.2 x86_64-linux-gtk2
Lazarus 4.1 (rev lazarus_4_0-96-gd9045ca6c5) FPC 3.2.2 x86_64-linux-gtk2

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #36 on: July 07, 2025, 10:21:28 am »
Strange... just tried it with a freshly compiled trunk and here it works:

Lazarus 4.99 (rev Unversioned directory) FPC 3.3.1 x86_64-linux-gtk2

So it must be fixed in trunk and not in the release versions.

(after moving the form)
Quote
Actieve LCL widgetset: (V)TGtk2WSCustomForm

Height: 321 (Count: 1)

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #37 on: July 07, 2025, 10:39:26 am »
Also couldn't confirm with freshly downloaded and installed Lazarus 4.0 from the home page (the .deb files).
Lazarus 4.0 (rev Unknown) FPC 3.2.2 x86_64-linux-gtk2


Grrr. can confirm with a correctly filled in TMainMenu.
« Last Edit: July 07, 2025, 10:42:14 am by rvk »

rvk

  • Hero Member
  • *****
  • Posts: 6886

MaartenJB

  • Full Member
  • ***
  • Posts: 119
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #39 on: July 07, 2025, 12:29:16 pm »
Probably related
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40443

Looks like it, they're mostly discussing if "height" should include mainmenu tho

I have two issues
1) Onresize triggers when it shouldn't (works fine in 2.2.6)
2) The value from "height/ClientHeight" is fluctuating when it shouldn't (works fine in 2.2.6)

The problem is I need one or the other to work around it. So probably the only viable option I got now is just use 2.2.6.
« Last Edit: July 07, 2025, 12:30:49 pm by MaartenJB »

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: [SOLVED] How to query the outer size of a 'TForm' ?
« Reply #40 on: July 07, 2025, 12:36:25 pm »
I have two issues
1) Onresize triggers when it shouldn't (works fine in 2.2.6)
2) The value from "height/ClientHeight" is fluctuating when it shouldn't (works fine in 2.2.6)
The onresize is triggered because internally the SetBounds get called multiple times with different sizes.
SetBounds is called when you do a move.
Normally when SetBounds is called with the same size, the onResize isn't called.
But if the size is different for both calls, it sees it as a resize, thus calling OnResize.

I think that's also the reason you get different ClientHeight, because for the first call, the height is different from the second.

Haven't found the reason why the SetBound is called twice for a WM_MOVE.

 

TinyPortal © 2005-2018