Jump to content
Sign in to follow this  
Freeeee

can a single unit have more than 1 form?

Recommended Posts

type
  TForm1 = class(TForm)

   TForm2 = class(TForm)

.......

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

   Form2:TForm2;

 

doesn't work BUT if you put the Type and Var statements + an 'end'  under "private'"  or "public"  it does compile.

 

Share this post


Link to post

It is not possible if you want to design the forms. The IDE will show only the visual design for one form. 1 pas + 1 dfm is the limit.

 

You can have multiple forms with the limitation that you create the components on the form in the code.

Share this post


Link to post

thanks.  I was coming to that conclusion.  

having a IDE designed around a forms design screen without allowing multiple forms seems like a bad idea.

I programmed in Turbo pascal on DOS and Win3 years ago and Delphi seemed to be a better product then.

much easier to use.

Am I correct in that that the 2nd and other forms have to go into either the public or private sections?

 

Share this post


Link to post
10 hours ago, Freeeee said:

having a IDE designed around a forms design screen without allowing multiple forms seems like a bad idea.

You can have multiple forms open in the IDE, each in its own unit. If you want multiple designers for each form, you need to create separate edit windows with New Edit Window.

 

10 hours ago, Freeeee said:

Am I correct in that that the 2nd and other forms have to go into either the public or private sections?

The usual way is to have a separate unit (pas and dfm) for each form. There are rare cases where declaring one or more form descendants in the same unit without the ability to design can make sense.

Share this post


Link to post

so I'd replace the *.DFM with specific, named dot DFM files?

by the way, that statement looks like a comment.  or is it a directive like {$-} and {$+} around I/O statements?

Or would I use the USE unit2, unit3, etc??

to gather the files.  

Is there some where I can look this stuff up in an Index?

 

 

Share this post


Link to post
6 minutes ago, Freeeee said:

so I'd replace the *.DFM with specific, named dot DFM files?

No, you should use separate units for each form and keep the {$R *.dfm} directive in each. The * makes it match with the unit name and the IDE will keep unit and form file names in synch.

 

Please refrain from packing multiple forms into one unit. Otherwise you will most likely flood this forum with questions about the problems you get, while the correct answer will always be: Don't do that!

  • Like 2

Share this post


Link to post

What version I using 12.2 and tried this IDE insight and it works well with the keyboard.

 

  • start Delphi
  • Press <F6> and enter VCL
  • Using down arrows select Windows Application
  • Press<F6> enter VCL select VCL form
  • Press<F6> Enter TButton 
  • Repeat above as needed.
  • Press<F6> Enter Help 

Share this post


Link to post

the reason I'm doing that is I have 3 separate but related pre-existing direct access files

that have to be kept in sync with each other.  I need 3 different forms in one program to do that.

So rather than "Don't Do That" what do you suggest?  we could to e-mail if you';d rather to keep the 

subject out of the forum but that seems to be contrary to the Forum concept.

 

I'm perfectly happy to have multiple units (dot pas files)    and then use the USES statement to 

collect them into 1 executable.

 

I did that years ago using  Turbo Pascal and Delphi version?  without much of a problem. 

That  code is corrupted or missing now. and it only ran on 16 bit DOS or WIN 3

But the files are still intact.

 

I'm trying to update it to a 64 bit world.    

 

 

 

 

Share this post


Link to post

There is no problem to have separate units for each form and still have them work together for whatever they are supposed to do. It is just difficult to give general advice instead of answering questions about a concrete problem.

 

Things that come to mind: Use a data unit (TDataModule or a plain unit) to group the file access at one place. Restrict the forms to the UI stuff and call the data unit classes or methods as appropriate. Ideally, each for unit only uses the data unit. I'm pretty sure there are ways to accomplish that.

 

 

Share this post


Link to post

What making One Application for now. And Run it Three times at a time.  

 

    set the Parameters     Data1.dat , Data2.dat, Data3 for first app.

    set the Parameters     Data2.dat , Data3.dat, Data1 for Second app.

    set the Parameters     Data3.dat, Data1.dat, Data2 for Third app.  

 

... procedure FindDeltas( const Param{1}, Param(2), Param(3));

   begin 

        Old code in here 

        

  end;

  

Is it a lazy steer that its 'looking' at?

       

Share this post


Link to post

thanks 

The data modules are new since I last used Turbo Pascal & Delphi

I'll look into it.  

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×