doubt about multiple forms

Posted on 2007-10-18
Last Modified: 2010-04-05
Hello guys,

I have a doubt, I have an application with a sales form, I need to open it more than 1 time,
this form is using a datamodule. Then imagine that I opened my form 10 times I also need to
create my datamodule 10 times too?

What is the best form to work with this?

Question by:hidrau
    LVL 4

    Accepted Solution

    I tell what i do...
    I have several datamodules that autocreate as application start.
    All other forms are not in autocreate mode. Obviously, except the mainform.
    Then as the user click here or there i create each form (and freed it when is not needed). An example of this:

    form1 := TForm1.Create(Application); //create the form in some menu or button click
    form1.ShowModal; //shows form1 for use
    form1.Free; //free the form
    form1 := nil; //ensures not garbage left

    Hope this can help you!!!
    LVL 17

    Assisted Solution

    Personally, I'd create only 1 TDataModule which has the Database on it, and any shared routines/classes/variables/queries that are not "window specific"
    Add this datamodule to the "uses" clause of the sales form.
    Place any "window specific" queries on the Sales Form, and set them to point to the datamodule's database component.
    then just go about creating multiple windows
    newform := TSalesForm.Create..... etc.
    This way, all the sales forms are usig the same database connection, but any specific queries are local only to that sales form.
    You can call the main datamodule for lookup values and standalone queries.
    LVL 1

    Author Comment

    To have the same windows several times opened, this is the suitable code:

    SalesForm := TSalesForm.Create(Self)

    in the event ondestroy

    SalesForm := nil

    am I on the right way?

    As I can see, I will have to have almost all my queries from my datamodule in the salesform. Because they are used for consulting. There is no way to have two form using the same query in different situation .

    The problem is that some query loads a bunch of rows and sometimes one query can have its size in memory 5 mb, then If I open 10 form I will have in memory 50 mb.

    LVL 4

    Expert Comment

    SalesForm.ShowModal, make the form modal. If you need to work no modal, and any session (form) has to have its own data, then you need diferent cursors of each table... Never try it, but perhaps you can keep the query in the datamodule and the datasource in salesform.
    But, really i have no experience in working with modeless form... as for my need, working with hundreds of paradox tables, i only use modal forms.
    LVL 15

    Assisted Solution

    I would use a single datamoulde and create each salesForm on the fly as you go.
    Also I would not have fixed query components on your datamodule but also create them as you go and use a single database object which they all connect through.
    LVL 1

    Author Comment

    Only a doubt about create window

    If I create a windows this way:

    Form1 := TForm1.Create(Self)

    All windows that will be create from Form1 must be in create : Application or Self ?
    LVL 17

    Assisted Solution

    either, it's not really going to matter.
    I'm assuming you have a "main form" that creates teh sales form? this would be the "self"
    so when that main form closes, it would close the sales forms..
    if you use application, then the forms will close when the application ends... pretty much the same thing if my guess on your application design is right.


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now