Lazarus

Programming => LCL => Topic started by: M+AUDIO on July 17, 2017, 09:45:32 am

Title: TForm.CreateNew Maximize Issue
Post by: M+AUDIO on July 17, 2017, 09:45:32 am
Hello,

A TForm created with CreateNew  constructor with AutoSize and MinSize and a control inside, refuses to maximize on win32 widgetset.
It will maximize however, after you resize the form by dragging borders a bit. but this is not correct.

Sample project attached. Lazarus SVN 32133 windows 7.
Title: Re: TForm.CreateNew Maximize Issue
Post by: Handoko on July 17, 2017, 10:17:22 am
I tested your code on both Linux64 and Win32 (using Wine). On Linux, it works as it should be. And yes, your issue happened on my test on Win32.

I found that the problem only happened if the form calls AutoSize. So the quick fix for it is to use Height instead of AutoSize.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   f: TForm;
  4.   e: TEdit;
  5. begin
  6.   f := TForm.CreateNew(Self);
  7.   e := TEdit.Create(f);
  8.   try
  9.     e.Parent := f;
  10.     f.Constraints.MinWidth := 300;
  11.     f.Height := e.Top + e.Height;
  12.     //f.AutoSize := True;   // <=== Remove the comment and the issue will come back
  13.     f.ShowModal;
  14.   finally
  15.     f.Free;
  16.   end;
  17. end;
Title: Re: TForm.CreateNew Maximize Issue
Post by: M+AUDIO on July 17, 2017, 11:00:33 am
Of course Handoko,
You can comment out  MinSize instead of AutoSize and it works too.
But the issue is still hiding back there.
Now you Confirmed it, it needs to be reported on the bug tracker, I guess.


P.S.
The reason I use TForm.AutoSize and alTop-ed controls inside for some small dynamic forms is High-DPI support. and it works really really good and automatic. (except this Maximize issue).
Title: Re: TForm.CreateNew Maximize Issue
Post by: Handoko on July 17, 2017, 11:55:52 am
I managed to make it works the way you want. Try the code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.     procedure NewFormActivate(Sender: TObject);
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. procedure TForm1.Button1Click(Sender: TObject);
  31. var
  32.   f: TForm;
  33.   e: TEdit;
  34. begin
  35.   f := TForm.CreateNew(Self);
  36.   e := TEdit.Create(f);
  37.   try
  38.     e.Parent := f;
  39.     f.Constraints.MinWidth := 300;
  40.     f.OnActivate := @NewFormActivate;
  41.     f.ShowModal;
  42.   finally
  43.     f.Free;
  44.   end;
  45. end;
  46.  
  47. procedure TForm1.NewFormActivate(Sender: TObject);
  48. var
  49.   h: Integer;
  50. begin
  51.   if not(Sender is TForm) then Exit;
  52.   with (Sender as TForm) do
  53.   begin
  54.     AutoSize := True;
  55.     h        := Height;
  56.     AutoSize := False;
  57.     Height   := h;
  58.   end;
  59. end;
  60.  
  61. end.

It works on my tests, it should work on your computer too. But I agree, there is a bug in AutoSize.
Title: Re: TForm.CreateNew Maximize Issue
Post by: taazz on July 17, 2017, 12:06:30 pm
Just to be clear. The bug is that the form maximizes with autosize set to true. It should not do that.
Title: Re: TForm.CreateNew Maximize Issue
Post by: Handoko on July 17, 2017, 12:14:10 pm
Form maximize + autosize behaves differently:
- On Linux, autosized form can be maximized
- On Windows, autosized form cannot be maximized
Title: Re: TForm.CreateNew Maximize Issue
Post by: taazz on July 17, 2017, 12:15:32 pm
Form maximize + autosize behaves differently:
- On Linux, autosized form can be maximized
- On Windows, autosized form cannot be maximized
linux has a bug. Autosize by design should not allow resizing the form. The only exception is when the form bigger than the supported size of the underline widget set (ee bigger that the desktop area in windows) in which case it will look like maximized but it should not be.
Title: Re: TForm.CreateNew Maximize Issue
Post by: M+AUDIO on July 17, 2017, 12:29:19 pm
linux has a bug. Autosize by design should not allow resizing the form.
But why? Delphi compatibility? IMHO it is better to allow resize. though the name AutoSize suggests otherwise.

@Handoko Yes that works, Thank you.
Title: Re: TForm.CreateNew Maximize Issue
Post by: taazz on July 17, 2017, 01:21:34 pm
linux has a bug. Autosize by design should not allow resizing the form.
But why? Delphi compatibility? IMHO it is better to allow resize. though the name AutoSize suggests otherwise.
Autosize and maximize are opposites. even partially maximized eg altop/left etc is outside the scope of autosize but could be interpreted as autosize the free to size dimension. maximize/alclient leave no free dimensions to size so you have to choose. maximize or autosize? it can't do both. If you leave it undefined then both actions are probable and you should not depend on either behavior.
Title: Re: TForm.CreateNew Maximize Issue
Post by: Ondrej Pokorny on July 18, 2017, 05:40:06 pm
Lazarus SVN 32133 windows 7.

Why so old? The current revision is 55526.
Title: Re: TForm.CreateNew Maximize Issue
Post by: M+AUDIO on July 19, 2017, 09:40:15 am
Lazarus SVN 32133 windows 7.

Why so old? The current revision is 55526.
Wow that was way off!  :o
Actually, I'm on 55489 (updated just before posting that). but somehow mysteriously I've wrote the number from Bug-ID column in TortoiseSVN's Show Log window.

Now I've reported it (https://bugs.freepascal.org/view.php?id=32164).
TinyPortal © 2005-2018