Cannot Create Form
Delphi Programming Language
Severity: CriticalWhat Does This Error Mean?
This error means Application.CreateForm failed during application startup, preventing the main form or a required form from being created. The application cannot start until this is resolved. Common causes include exceptions in the form constructor, missing components, or DFM loading failures.
Affected Models
- Delphi 10.4 Sydney
- Delphi 11 Alexandria
- Delphi 12 Athens
- Embarcadero RAD Studio
- Free Pascal / Lazarus
Common Causes
- An exception is raised inside the form's OnCreate event or constructor, aborting form creation
- The DFM file for the form cannot be loaded because of a missing component class or corrupt DFM
- Initialization code in the DPR file raises an exception before CreateForm is called
- A required external resource (database, file, registry key) is missing and accessed during form creation
- The form class is not registered because its unit is not included in the project
How to Fix It
-
Run the application in the Delphi debugger with 'Stop on Delphi exceptions' enabled (Run → Debugger Options → Language Exceptions). The debugger will stop at the inner exception that caused CreateForm to fail.
The 'Cannot create form' message is a wrapper — the real cause is the inner exception that fired during form creation.
-
Look at the call stack when the debugger stops. Find the first line of your own code in the stack — that is where the creation failed. Common locations: OnCreate event, FormCreate handler, or component initialization.
The call stack shows the complete chain from Application.CreateForm down to the failing line.
-
Move all code that can fail out of FormCreate and into later events or lazy initialization. FormCreate should be fast and safe. Defer database connections, file access, and network calls to FormShow or the first use.
If the application requires a database at startup, show an error and allow the user to configure the connection rather than crashing.
-
If the DFM fails to load, the error is usually about a missing component class. Check that all required packages are linked into the project and that every component class used in the DFM is available.
Missing component classes cause EFilerError or EReadError inside CreateForm, which is then reported as 'Cannot create form'.
-
Check the project DPR file for initialization code that runs before CreateForm. Any exception in unit initialization sections (the initialization begin...end block) will prevent CreateForm from being reached.
Unit initialization sections run at program start before any application code. An exception there is fatal and surfaces as a startup failure.
When to Call a Professional
Cannot create form is a critical startup failure. Run the application in the Delphi debugger to see exactly which exception fires and on which line. The debugger will stop at the exception inside the form creation process, showing you the exact cause. Do not ship a fix without fully understanding and resolving the root exception.
Frequently Asked Questions
The application worked yesterday — what could have changed?
Common causes of sudden CreateForm failure are: a missing or changed external resource (database server, configuration file), a DLL or package that was updated or removed, or a recent code change that introduced an exception in OnCreate. Check what changed since the last working run — new code, new deployment, changed environment.
How can I show a user-friendly error instead of crashing?
Wrap Application.CreateForm in a try/except in the DPR file's begin...end block. Catch the exception, show a message, and optionally write to a log file before calling Application.Terminate. This gives users a readable error rather than a cryptic crash dialog.
Can this error happen in already-installed applications when the user's environment changes?
Yes. If the form's OnCreate connects to a database, opens a file, or reads a registry value, changes in the user's environment can cause it to fail. Design applications to handle missing resources gracefully at startup — show a configuration dialog rather than crashing.