MDI Application

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Sawlmgsj
Posts: 35
Joined: Thu 11 Nov 2004 08:35

MDI Application

Post by Sawlmgsj » Sun 08 Jun 2008 05:38

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.

tinof
Posts: 39
Joined: Fri 16 Dec 2005 07:41

Post by tinof » Mon 09 Jun 2008 05:51

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

tinof
Posts: 39
Joined: Fri 16 Dec 2005 07:41

Post by tinof » Mon 09 Jun 2008 06:42

edit: double - post
Last edited by tinof on Mon 09 Jun 2008 11:07, edited 1 time in total.

Sawlmgsj
Posts: 35
Joined: Thu 11 Nov 2004 08:35

Post by Sawlmgsj » Mon 09 Jun 2008 10:35

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.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 10 Jun 2008 07:44

That made me wounder whether I ought to use separate TMSConnection's, that is one for each MDI child form.
It is not necessary because a default MDI application is running in a single thread.

Sawlmgsj
Posts: 35
Joined: Thu 11 Nov 2004 08:35

Post by Sawlmgsj » Tue 10 Jun 2008 07:55

Dear Antaeus,

Many thanks for the clarification.

Regards,
Steve.

Post Reply