Difference between revisions of "RequireDerivedFormResource"

From Lazarus wiki
Jump to navigationJump to search
 
Line 7: Line 7:
 
* Construct your form using the <tt>CreateNew()</tt> [[Constructor|constructor]].
 
* Construct your form using the <tt>CreateNew()</tt> [[Constructor|constructor]].
 
* Disable the exception by setting the global variable RequireDerivedFormResource to False.
 
* Disable the exception by setting the global variable RequireDerivedFormResource to False.
 +
 +
RequireDerivedFormResource is automatically inserted on creating a new form in the [[IDE]].
 +
 +
<syntaxhighlight lang=pascal>
 +
begin
 +
  RequireDerivedFormResource:=True;
 +
  Application.Scaled:=True;
 +
  Application.Initialize;
 +
  Application.CreateForm(TForm1, Form1);
 +
  Application.Run;
 +
end.                       
 +
</syntaxhighlight>
 +
  
 
[[Category:Forms]]
 
[[Category:Forms]]

Latest revision as of 20:52, 28 August 2021

RequireDerivedFormResource is a switch to toggle the requirement for a TForm's resource

Each form created by the IDE should have a resource, so if resource is not found there is something wrong with either a resource or the unit which contains the faulty form. Therefore the application should inform the developer that the form can't function correctly without the resource. This change is also Delphi compatible and compatible with TFrame and TDataModule components.

If you need a resourceless form you have 3 options:

  • Create a TForm class (not a descendant)
  • Construct your form using the CreateNew() constructor.
  • Disable the exception by setting the global variable RequireDerivedFormResource to False.

RequireDerivedFormResource is automatically inserted on creating a new form in the IDE.

begin
  RequireDerivedFormResource:=True;
  Application.Scaled:=True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.