Author Topic: CreateForm() vs Form.Show  (Read 468 times)

dodgebros

  • Full Member
  • ***
  • Posts: 171
CreateForm() vs Form.Show
« on: September 18, 2026, 09:33:17 pm »
What does CreateForm() do if I have already created the form in the IDE?

Also, what is the difference between CreatForm() and Form.Show?

Thanks and good to be writing code again!

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1618
    • Lebeau Software
Re: CreateForm() vs Form.Show
« Reply #1 on: September 18, 2026, 09:52:53 pm »
What does CreateForm() do if I have already created the form in the IDE?

It creates a new instance of the specified Form class. It does not care if an instance already exists or not. If you want only 1 instance to exist at a time, you have to write code to manage that.

Also, what is the difference between CreatForm() and Form.Show?

CreateForm() simply creates a new Form instance, nothing more. Whether the new Form instance will be visible or not depends on its Visible property at design-time, or in the case of creating the MainForm, on the Application.ShowMainForm property.

Show() simply makes a Form instance be visible if it is not already visible.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

dodgebros

  • Full Member
  • ***
  • Posts: 171
Re: CreateForm() vs Form.Show
« Reply #2 on: September 19, 2026, 05:19:58 am »
Thanks !
TD

jamie

  • Hero Member
  • *****
  • Posts: 8071
Re: CreateForm() vs Form.Show
« Reply #3 on: September 19, 2026, 04:59:34 pm »
There is also createNew which creates the form but does not read the Resource file, basically you need to define all the properties in code that do not fit your default values.

Jamie
The only true wisdom is knowing you know nothing

Weiss

  • Sr. Member
  • ****
  • Posts: 259
Re: CreateForm() vs Form.Show
« Reply #4 on: October 04, 2026, 11:38:58 am »
dodgeBros, form is created perhaps once when application start, unless you specifically force destroying it for some reason.
Code: Pascal  [Select][+][-]
  1. close;
does not destroy form. When application is already running, form will "show" every time you close and re-open the form, or re-size the window.

I learned the difference not long ago myself. Good to know, in case your form reflects some continually changing underlaying data, then run the update routines when form "show".

n7800

  • Hero Member
  • *****
  • Posts: 810
  • Lazarus IDE contributor
    • GitLab profile
Re: CreateForm() vs Form.Show
« Reply #5 on: October 04, 2026, 11:41:44 pm »
"close;" does not destroy form. When application is already running, form will "show" every time you close and re-open the form, or re-size the window.

Note that the behavior differs. If it is the "main" window (usually the first form created), calling "Close" will terminate the application (even if other windows are open). If it is a secondary window, it is hidden by default and can be reopened with a simple "Show" without creating it again.

 

TinyPortal © 2005-2018