[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] |
Creates a Form or component owned by the Application instance.
Source position: forms.pp line 1603
public procedure TApplication.CreateForm( |
InstanceClass: TComponentClass; |
out Reference |
); |
InstanceClass |
|
The class type used to create the new class instance. |
Reference |
|
The output parameter used to return the new component reference. |
Remark: | The method name is slightly misleading, and kept only for Delphi compatibility. The method can actually create any kind of component. |
CreateForm creates a new Component instance of the given class, and sets the pointer to the component variable in Reference. If InstanceClass is a TForm descendant, it will be added to the list of forms in the application. It is assigned as the MainForm in Application if a form has not already been assigned to the property. A form with its FormStyle property set to fsMDIChild or fsSplash is not used as the MainForm for the Application.
If the new form instance is a splash form (FormStyle=fsSplash), it is displayed immediately and a message processing loop is started for the form instance.
Use in a .lpr Project File
The most common use of CreateForm is in the project (.lpr) program file. It is used to initialize the auto-created form instances for the project. For example:
program PoFileMaintenance; {$mode objfpc}{$H+} uses {$IFDEF UNIX} cthreads, {$ENDIF} {$IFDEF HASAMIGA} athreads, {$ENDIF} Interfaces, Forms, PotFile, Unit1, { you can add units after this }; {$R *.res} begin RequireDerivedFormResource := True; Application.Scaled := True; Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.
Use in Program Code
Another common use of CreateForm is to allocate a dynamic, temporary form instance as needed in program code. For example:
function ShowDialog(FormClass: TFormClass): Boolean; var Dlg: TForm; begin Application.CreateForm(FormClass, Dlg); try Result := Dlg.ShowModal in [mrOk, mrYes]; finally Dlg.Free; end; end;
|
Contains the main form for the application. |
|
|
Makes the specified form the MainForm in the Application. |
|
|
Call this method during lengthy operations to ensure the GUI remains responsive. |
|
|
Indicates the style for the form. |
|
|
Displays the form instance with support for High DPI scaling. |
Version 4.0 | Generated 2025-05-03 | Home |