Recent

Author Topic: Determining which forms are shown at startup  (Read 11392 times)

jack

  • Full Member
  • ***
  • Posts: 107
Determining which forms are shown at startup
« on: March 08, 2012, 03:48:22 am »
How do I determine which Forms are shown at startup time?

I have one that has started to appear when the ap starts (in addition to Form1)

Thanks for yor help.
« Last Edit: March 08, 2012, 04:02:47 am by jack »

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: Determining which forms are shown at startup
« Reply #1 on: March 08, 2012, 06:19:17 am »

Go to Project -> Project Options , under Project Options tree, find Forms.
On left side you can choose Auto-create forms and on right side you can put all other.
Lazarus 3.6 on Windows 11

jack

  • Full Member
  • ***
  • Posts: 107
Re: Determining which forms are shown at startup
« Reply #2 on: March 08, 2012, 06:10:51 pm »
Thank You for your reply, it helps me understand more about this and helps me more clearly ask my question.
Let me rephrase my question:

By default the IDE sets up all eleven of my forms to be created at start-up.
During the development process, only Form1 has been visible at start-up.  I came to expect this behavior as normal.  Suddenly Form9 has also been Visible at start-up.

My question is how is this behavior managed?  Where do I go to make Form9 hidden at start-up like the other sibling forms?

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Determining which forms are shown at startup
« Reply #3 on: March 08, 2012, 11:21:29 pm »
focus on Form9, and find the Object Inspector property for Form9 called "visible".  Make sure it's value is set to False.

You could also do this during the program startup code you have.

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: Determining which forms are shown at startup
« Reply #4 on: March 09, 2012, 03:13:20 am »
Hi,

Quote
By default the IDE sets up all eleven of my forms to be created at start-up.
This is not the best thing to do - one of the reason not to do it, you already wrote.

One kind of solution is to leave only the first, main form (Form1) to be automatically created and to create all the other forms from code like :
Code: [Select]
  Form1 := TForm1.Create(nil);
  Form1.ShowModal;
  Form1.Release;


Using this kind of form creation you can take over more control of the application you wrote , especially if you use database to store or recall some data. Of course  , this method needs to move all forms, except form1, in Project Options, from auto-create field to available forms field.
« Last Edit: March 09, 2012, 04:07:16 am by bambamns »
Lazarus 3.6 on Windows 11

jack

  • Full Member
  • ***
  • Posts: 107
Re: Determining which forms are shown at startup
« Reply #5 on: March 09, 2012, 06:18:12 am »
Of course you were right the Visible property was set to true for form9.

In reviewing your response I see the merit in taking charge of the form creation process etc...  This raises a couple of questions.

What is the difference between:
Form.Hide and Form.Close?
Form.Show and Form.ShowModal ?
Form.Close and Form.Release

I have been able to redisplay a form which I 'Closed' and a Form which I have 'Hidden' with the same Method 'Form.Show'. 

I have not had to issue a Form.Create which would seem to be the antithesis of Form.Close. (but perhaps it is Form.Release?)

I have noticed that Queries on the Form are not refreshed unless I issue the command.  Would the form creation process re-query those TSQLQuery objects on the Form? 

I recognize that these seem like novice questions and in this context I am a novice. Is there a discussion of best practices at a novice level to be studied?

Definitions are difficult, there being no documentation on-line.  Its a bit like learning a foreign language by immersion.  One either asks a lot of questions or hides. 

I am grateful for this forum of native Lazarus speakers to help out.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Determining which forms are shown at startup
« Reply #6 on: March 09, 2012, 10:11:13 am »
If you want to destroy a form when closing, that would be for example:
Code: [Select]
FreeAndNil(form9);or same thing longer:
Code: [Select]
form9.Free;
form9:=nil;

Assume the .Release command would destroy it, all references to that form would not automatically NIL themselves.

ShowModal you need to try to see exactly what it means. It is used to get a result from a form through ModalResult, which is also given in that ShowModal() function result. Modal form doesn't let you activate its parent forms while shown.

Example:
Code: [Select]
if form9.ShowModal = mrOK then begin
  // User pressed OK to close it
end;
And as you can see, where .Show would execute all commands after it, ShowModal will stop and wait until the form is closed.
« Last Edit: March 09, 2012, 10:14:00 am by User137 »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4698
  • I like bugs.
Re: Determining which forms are shown at startup
« Reply #7 on: March 09, 2012, 11:17:40 am »
What is the difference between:
Form.Hide and Form.Close?
Form.Show and Form.ShowModal ?
Form.Close and Form.Release

Hide hides and Close closes :)
In practice the graphical window or dialog does not exist any more after Close, although the LCL object is still there.

I don't know what "Release" does, never used it myself. Typically you use "Free" to release the LCL object's memory.
"Create" and "Free" are a pair, "Show" and "Close" are another pair (in a way).

Quote
I have been able to redisplay a form which I 'Closed' and a Form which I have 'Hidden' with the same Method 'Form.Show'. 

If you "Close" a form and then "Show" it, the form is effectively created as a new form.
If you "Hide" a form and then "Show" it, the same minimized form becomes visible again.
You can test it with an edit control on the form. Type something on the control and Close the form, and the text is gone. Hide the form and the text is still there.

Quote
I have not had to issue a Form.Create which would seem to be the antithesis of Form.Close. (but perhaps it is Form.Release?)

"Create" <-> "Free".
"Show" <-> "Close".
The form must be created somewhere. For auto-created forms it happens in the project's .lpr file as:
  Application.CreateForm(TForm1, Form1);

You should also learn the purpose of "Owner" and "Parent".
"Owner" is about memory management.
"Parent" is about visual containers.
Googling "Delphi Owner Parent" found for example:
  http://delphi.about.com/od/objectpascalide/a/owner_parent.htm

Quote
Definitions are difficult, there being no documentation on-line.  Its a bit like learning a foreign language by immersion.  One either asks a lot of questions or hides. 

There is an effort to improve LCL documentation. Now you can use Delphi's documentation which is quite good. Just include "Delphi" into your Google search and you get lots of matches.

Juha
« Last Edit: March 09, 2012, 11:29:09 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: Determining which forms are shown at startup
« Reply #8 on: March 11, 2012, 06:48:35 am »
With forms, the Release method should be used instead of the Free
method. Basically, what you could do is this:

  Form1.Release;
  Form1 := nil;

In case you want your form to be nil afterwards.

Why use release?
Simple. A form is receiving messages from the systems
and it might be busy processong one or more of those messages. Even
after you use 'Close', the form will just call 'Release' when it is
about to free itself. (Besides, 'Close' doesn't always free your form.
This behaviour depends on the CloseAction.)
So what if you free a form instead of releasing it? Well, it means
that some messages that should be handled by the form will not be
handled. Event handlers that are still active will also suddenly
terminate. If not, the result can be some nasty memory problems and
access violations afterwards.

The code that I've put above will work just fine. The Release command
will make sure the form gets freed eventually. By assigning Nil to the
Form variable, you can see if the form is unavailable now.
Lazarus 3.6 on Windows 11

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4698
  • I like bugs.
Re: Determining which forms are shown at startup
« Reply #9 on: March 18, 2012, 06:49:39 pm »
bambamns, you are right about the Release method.
I forgot it because I never really use it. I free only modal forms, modeless forms are typically freed at the end of application.
The fact however is that Free works well after Showmodal. It is used a lot in Lazarus code, too, and not only in parts made by me.
Why it works well, I don't know. Mayby someone else knows.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018