Lazarus

Programming => LCL => Topic started by: jamie on June 19, 2019, 10:52:03 pm

Title: Setting BoundsRect locked out within OnCreate of form if not using poDesign.
Post by: jamie on June 19, 2019, 10:52:03 pm

When did this inability of Setting the BoundsRect inside of the OnCReate of a form stop
working if you are not using poDesign for the POSITION property?

  I had my forms set to poDefault and while that uses the OS suggested position for your
form, I still need to be able to set it from my config file when starting the app..

 The only time I don't set it is if I don't yet have a config file or the entry isn't in there, therefor
I can allow the OS to pick A location for the initial position of the form..

  The setting of the POSITION property "boundsrect" should respect what I want to
do while in the OnCreate event and if I chose not to set it, it'll  use the OS settings.

 If I use poDesign it will allow me to set it but then again, if the app runs the first time on a
PC with a different screen layout It may not fit!..


Title: Re: Setting BoundsRect locked out within OnCreate of form if not using poDesign.
Post by: Zoran on June 20, 2019, 12:34:08 am
Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if FoundConfigFile then begin
  4.     Position := poDesigned;
  5.     top := 500; // what you read from config file
  6.     Left := 800;
  7.   end else
  8.     Position := poDefault;
  9. end;
Title: Re: Setting BoundsRect locked out within OnCreate of form if not using poDesign.
Post by: jamie on June 20, 2019, 03:21:19 am
In the past I didn't have to change the Position property within the Event to do this..

 basically the form should be setting the boundsRect before the OnCreate event is called and if
the code in the OnCreate decides to change it again so be it.

  But that isn't what's happening..

   Although I can work around this, as pointed out by you, I shouldn't need to do this.

  This has to be a change that was done in a recent release of Laz because I don't remember
seeing this before.

 I made a class derived from TInifile that has a TIniFileEx.WriteRect(Section, Key:String; Value:TRect);

 The reading part accepts a Default TRECT which is the current BoundsRect of the form if
the value does not yet exist in the file. So this stands the reason why the TFORM.OnCreate
should already have a valid BoundsRect setup before this event.

 I will need to do some more research...
Thanks.


 TiniFileExe

Title: Re: Setting BoundsRect locked out within OnCreate of form if not using poDesign.
Post by: Thaddy on June 20, 2019, 08:14:04 am
So this stands the reason why the TFORM.OnCreate
should already have a valid BoundsRect setup before this event.
Theoretically you have only three solid options:
- In the constructor of your form.
- In the AfterConstruction of your form
- In the OnCreate Event itself

Any other options that may have worked (e.g. onpaint, onshow) are by accident.
Title: Re: Setting BoundsRect locked out within OnCreate of form if not using poDesign.
Post by: jamie on June 23, 2019, 10:03:52 pm
For now  I used Zoran's idea.

R := BoundsRect;
Position := poDesigned;

BoundsRect := SetUpini.ReadRect(Section, FormBoundsRectKey, R);


This way I have the form startup in poDefault, get the suggested bounds as the default and
use it as a Default if the key does not yet exist in the INI file.

btw, I sub classed the TiniFIle and added some bells and ding dongs to it..