0

I want to create form as a local variable in a procedure and then open it in a design mode so I can add components to it. Is this possible or do I have to create whole new unit to do this?

2 Answers2

2

The IDE form-designer can only handle a form created it its own unit. So yes, you need a "whole new unit", as you put it, assuming you have not already created it.

The best place for your procedure with the local variable to go is a separate issue. Obviously, if it is a method of another form, it will need to be in that other form's unit, but otherwise it should in in wherever is the best place for it, "best" taking account of considerations like maintainability, clarity, logical organisation, etc.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • Thank you, I'm gonna do that. –  Oct 23 '17 at 11:21
  • It's unclear whether the code that instantiates the form at runtime should be in the same unit that declares the form, or not. No way that we can give that advice. So, don't just put it in the same unit because @MartynA says you can do so. Put it in the right place, as you see fit looking at the rest of your architecture. – David Heffernan Oct 23 '17 at 11:25
  • @DavidHeffernan: I completely agree that it should go in the right place, wherever that happens to be and wasn't intending to suggest otherwise, only that if is a method of another form, it will necessarily not be in the same unit as the form which the OP asked about. – MartynA Oct 23 '17 at 11:35
  • I was just clarifying for the benefit of the asker who, as is so often the case, taken your bald statement to be a recommendation. – David Heffernan Oct 23 '17 at 11:37
  • @DavidHeffernan: Sure, I will adorn my statement with some hair. – MartynA Oct 23 '17 at 11:39
1

Is this possible or do I have to create whole new unit to do this?

You have to create a new unit to do this.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490