I am creating a Windows Forms MDI application (multiple document interface).
I have a number of different tables (sellers, purchasers, orders etc).
I want to be able to create a number of instances of each one (a form with a tabbed page showing various aspects of a record) to manipulate a particular record. Therefore I may have open a number of the same type of record (e.g. sellers), but I shall prevent the operator from opening two instances of the same record on different forms.
Do I need to have a TMSConnection on each form? Is there any downside to having a number of TMSConnection components open in an application?
Thanks,
Steve.
MDI Application
Hi,
i do it in this way :
Create a datamodule, an place one connection for any database you need in your application on it (maybe only 1 conn), let's call us "DM_Main".
Do in the OnCreate() Event pf your mainform :
..
DM_Main := TDM_Main.Create
{ do something to open the database(s) - username, password ...
or do it within the OnCreate() - Event of the Datamodule
Open the connections
}
..
Now you have the connection(s) active you can use in every Form of your app. Include the Datamodule in all forms you need :
Uses ... [Datamodule_filename] ...
After doing so, you can choose the one connection in your MSQueries / MSTables in all Forms. You have not to create and open a Connection in every Form.
Note, the Datamodule must be opened in the IDE, to select its
connections in the forms.
For the second problem (avoid working with the same record in dífferent forms) i don't know a simple solution.
In non critical areas (sellers, articles ..) i don't care - the last post wins.
In critical areas (orders) i have a 'Lock' - table. If the user starts to edit a record, i place a lock - record with tablename + primary key in the lock table. Previously i check, that there is no such record from an other form. If the is another record i can tell it the user.
After post of maintable i delete the record.
I'm sure, there is a better solution, but that's the way i do it.
Tino
Greetings
i do it in this way :
Create a datamodule, an place one connection for any database you need in your application on it (maybe only 1 conn), let's call us "DM_Main".
Do in the OnCreate() Event pf your mainform :
..
DM_Main := TDM_Main.Create
{ do something to open the database(s) - username, password ...
or do it within the OnCreate() - Event of the Datamodule
Open the connections
}
..
Now you have the connection(s) active you can use in every Form of your app. Include the Datamodule in all forms you need :
Uses ... [Datamodule_filename] ...
After doing so, you can choose the one connection in your MSQueries / MSTables in all Forms. You have not to create and open a Connection in every Form.
Note, the Datamodule must be opened in the IDE, to select its
connections in the forms.
For the second problem (avoid working with the same record in dífferent forms) i don't know a simple solution.
In non critical areas (sellers, articles ..) i don't care - the last post wins.
In critical areas (orders) i have a 'Lock' - table. If the user starts to edit a record, i place a lock - record with tablename + primary key in the lock table. Previously i check, that there is no such record from an other form. If the is another record i can tell it the user.
After post of maintable i delete the record.
I'm sure, there is a better solution, but that's the way i do it.
Tino
Greetings
Dear Tino,
Thank you for your comments.
The method you have described is essentially my normal method as well.
However, I have noted these comments by Antaeus on this matter:
"Probably you have encountered the problem with SQL Server locking. You should not use FetchAll=False mode in your datasets, as underfetched datasets may lead to the locking issues.
Another possible reason is incorrect working with SDAC in multiple threads. You should use one TMSConnection object in each thread, and enable pooling for each TMSConnection. Pooling will help you to increase performance of your application."
That made me wounder whether I ought to use separate TMSConnection's, that is one for each MDI child form.
Regards,
Steve.
Thank you for your comments.
The method you have described is essentially my normal method as well.
However, I have noted these comments by Antaeus on this matter:
"Probably you have encountered the problem with SQL Server locking. You should not use FetchAll=False mode in your datasets, as underfetched datasets may lead to the locking issues.
Another possible reason is incorrect working with SDAC in multiple threads. You should use one TMSConnection object in each thread, and enable pooling for each TMSConnection. Pooling will help you to increase performance of your application."
That made me wounder whether I ought to use separate TMSConnection's, that is one for each MDI child form.
Regards,
Steve.