10

When designing a TForm, a line is added to the form's unit declaring the form object...

var
  frmMyForm: TfrmMyForm;

I don't need this form auto-created, and I intend to create multiple instances of it, and to make sure I don't make the mistake of using this declared form, I commented it out...

//var
  //frmMyForm: TfrmMyForm;

I was wondering if this is safe to do? I don't see any problems, and the form designer still works fine. But could there be some trouble if I leave this out completely?

TLama
  • 75,147
  • 17
  • 214
  • 392
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327

1 Answers1

15

This is a very common scenario when using form inheritance. You normally don't want to instantiate derived forms from the middle of the inheritance chain.

The only place where these form variables are used (besides your code perhaps) is the dpr file and that only when the form is autocreated.

So, no problem to remove the declaration.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • And keep an eye on fixed links established via the object inspector between forms. tbl1 : tTable declared in frmMyForm, tds1 : tDatasource declared in an other form. Object inspector is using the variable name **frmMyForm** in front of tbl1.`---` Check is only done when making the link. If you remove the declaration after the link was established you will face an error at runtime. – Ali Avcı Sep 03 '12 at 11:23
  • AFAIK, the OI links are bound to the component name and not to the component variable declared in the code. So yes, the form or datamodule has to be instantiated when the link is resolved, but the declaration is only necessary when some source code references it. – Uwe Raabe Sep 03 '12 at 11:30