Board index » delphi » Some weird behaviour of datamodules...

Some weird behaviour of datamodules...

with Delphi 2.0 I prefer working with datamodules. In a project
consisting of several applications it is the only way to be sure the
'rules' of the database are everywhere equally implemented.

But a strange bevaviour of the Datamodules occured to me.
In a MDI application the navigation within the datamodules is
'linked'. for example. I have two forms with lets say client
information. When i go to the 'next' record in form 1, also form 2
shows the next record. This behaviour did not occur when I still
plastered my forms with tables and datasources.

I've tried several ways (creating the datamodule from the form using
it) to 'trick' the datamodule, but up until now i did not succeed.

Because -as I told before- I do like datamodules, 'plastering tables
on the form' is no solution to me, so please does anyone know how to
create seperate instances of the datamodule for each MDI form ???

ATDT Consultancy
Postbus 370
7300 AJ Apeldoorn
tel 055-5340911
URL : http://www.xs4all.nl/~atdt
E-Mail : i...@atdt.nl

 

Re:Some weird behaviour of datamodules...


Well, let's think about this.......

Even thought you are opening multiple instances of a form, you are
NOT opening multiple instances of your data module(or the objects inside it
for that matter..)

All of the 'Data Aware' controls on your mdi childr forms ARE linked to ONE
Data Module and the components within them.

You need to create a new instance of your Data Module for each mdi child
you create, OR, you can try to get fancy with the sql each time you set
focus to a new form, but that could be tricky..

Or, you could go back to the old way of putting all the stuff on the
form....  Have fun!!

+--------------------------------------------------+
Shawn K. Clark
scl...@illuminet.net
scla...@csc.com
http://www.illuminet.net/~sclark
+--------------------------------------------------+

Wilko van der Ploeg <w...@xs4all.nl> wrote in article
<4skvqb$...@news.xs4all.nl>...

Quote
> with Delphi 2.0 I prefer working with datamodules. In a project
> consisting of several applications it is the only way to be sure the
> 'rules' of the database are everywhere equally implemented.

> But a strange bevaviour of the Datamodules occured to me.
> In a MDI application the navigation within the datamodules is
> 'linked'. for example. I have two forms with lets say client
> information. When i go to the 'next' record in form 1, also form 2
> shows the next record. This behaviour did not occur when I still
> plastered my forms with tables and datasources.

> I've tried several ways (creating the datamodule from the form using
> it) to 'trick' the datamodule, but up until now i did not succeed.

> Because -as I told before- I do like datamodules, 'plastering tables
> on the form' is no solution to me, so please does anyone know how to
> create seperate instances of the datamodule for each MDI form ???

> ATDT Consultancy
> Postbus 370
> 7300 AJ Apeldoorn
> tel 055-5340911
> URL : http://www.xs4all.nl/~atdt
> E-Mail : i...@atdt.nl

Re:Some weird behaviour of datamodules...


"Shawn K. Clark" <scl...@illuminet.net> wrote:

Quote
>All of the 'Data Aware' controls on your mdi childr forms ARE linked to ONE
>Data Module and the components within them.
>You need to create a new instance of your Data Module for each mdi child
>you create, OR, you can try to get fancy with the sql each time you set
>focus to a new form, but that could be tricky..

I already tried that, but even if I created a new (private) instance,
it did not work... they were stil linked.

Quote
>Or, you could go back to the old way of putting all the stuff on the
>form....  Have fun!!

Tanks...

Wilko van der Ploeg
ATDT Consultancy
The Netherlands
homepage : http://www.xs4all.nl/~atdt

Re:Some weird behaviour of datamodules...


Quote
>>Or, you could go back to the old way of putting all the stuff on the
>>form....  Have fun!!
>Tanks...

Well... slip of the keyboard... thanks of course...
Wilko van der Ploeg
ATDT Consultancy
The Netherlands
homepage : http://www.xs4all.nl/~atdt

Re:Some weird behaviour of datamodules...


In article <4skvqb$...@news.xs4all.nl>,
   w...@xs4all.nl (Wilko van der Ploeg) wrote:

Quote
>Because -as I told before- I do like datamodules, 'plastering tables
>on the form' is no solution to me, so please does anyone know how to
>create seperate instances of the datamodule for each MDI form ???

I did some experiments, and was unable to find any way around this
irritating behavior. It is possible to use a datamodule, even if you delete
the global instance variable. It only seems to require that one exist
somewhere -- anywhere -- in the application space. But all the instances
(say of multiple MDI child forms) will only use the first instance. I  seem
to remember reading somewhere that they automatically instantiate a
datamodule and binds the data aware components to that instance, creating
one if necessary -- but I couldn't find this in a brief search.

Can someone provide a reference in the VCL to where the datamodules are
automatically bound to their referents?

It may be possible to do a very simple little patch that would allow each
form to get its own datamodule. (For example, if it is looking for the
first match in a list, it might be possible to force a new instance into
the beginning of the list, thus tricking the search.)

Of course you can always declare a form variable of the datamodule's type,
and create an instance, but that doesn't connect the components to that
datamodule instance -- the work-around, which I've also tried, is assigning
all the values (Datasource, etc.) at run time. That is a royal pain in the
butt, and in many cases breaks your forms at design time (so you can't
verify SQL is correct, and similar things), so I wouldn't recommend it. An
intermediate solution, is putting datasources on forms, and datasets on
datamodules.

--
Brad Aisa <ba...@tor.hookup.net>  http://www.hookup.net/~baisa/

"The highest responsibility of philosophers is to serve as the
guardians and integrators of human knowledge."   -- Ayn Rand

Re:Some weird behaviour of datamodules...


In article: <01bb75bd$4c485c60$5d650...@stimpy.backlick.csc.com>  "Shawn K. Clark"

Quote
<scl...@illuminet.net> writes:

[snip]

Quote

> You need to create a new instance of your Data Module for each mdi child
> you create, OR, you can try to get fancy with the sql each time you set
> focus to a new form, but that could be tricky..

> Or, you could go back to the old way of putting all the stuff on the
> form....  Have fun!!

Am I missing something? Why not put multiple tables/queries etc. in a
single data module and configure these to share the same 'business
rules' code. If the maximum number of child windows is unknown at
compile time or is unreasonably high then why not create TTables,
etc. when the child window is created and assign the properties and
events from the corresponding instances in the data module?

--
Chris Isbell               Southampton, England
ch...@kenda.co.uk (work)   ch...@isbell.demon.co.uk (home)
+44 1703 869922            +44 1703 465367

Re:Some weird behaviour of datamodules...


Quote
In article <225738305...@kenda.co.uk>, ch...@kenda.co.uk wrote:
>In article: <01bb75bd$4c485c60$5d650...@stimpy.backlick.csc.com>  "Shawn K.
> Clark"
><scl...@illuminet.net> writes:

>[snip]

>> You need to create a new instance of your Data Module for each mdi child
>> you create, OR, you can try to get fancy with the sql each time you set
>> focus to a new form, but that could be tricky..

>> Or, you could go back to the old way of putting all the stuff on the
>> form....  Have fun!!

>Am I missing something? Why not put multiple tables/queries etc. in a
>single data module and configure these to share the same 'business
>rules' code. If the maximum number of child windows is unknown at
>compile time or is unreasonably high then why not create TTables,
>etc. when the child window is created and assign the properties and
>events from the corresponding instances in the data module?

I tried this, it gave me a big pain in the ....

Can you give an example?

Happy Hacking The Graphical Gnome

----------------------------------------------
| Rob den Braasem    | Voice :-31-79-3531520 |
|                    | Fax   :-31-79-3513561 |
|                    | Mail  : r...@ktibv.nl  |
|                    |-----------------------+---------------------+
| KTI bv             | "I die when it's time for me to die.        |
| P.O. Box 86        | So let me live  my life the way I want to." |
| 2700 AB Zoetermeer |                                             |
| The Netherlands    |   Jimi Hendrix                              |
-------------------------------------------------------------------+

Other Threads