doubt about multiple forms

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?

thanks
LVL 1
hidrauAsked:
Who is Participating?
 
Martin BarredaLic. in Computer ScienceCommented:
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!!!
0
 
TheRealLokiSenior DeveloperCommented:
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.
0
 
hidrauAuthor Commented:
To have the same windows several times opened, this is the suitable code:

SalesForm := TSalesForm.Create(Self)
SalesForm.Show

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.

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Martin BarredaLic. in Computer ScienceCommented:
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.
0
 
mikelittlewoodCommented:
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.
0
 
hidrauAuthor Commented:
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 ?
0
 
TheRealLokiSenior DeveloperCommented:
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.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.