Board index » delphi » Question about instantiating datamodules for MDI forms

Question about instantiating datamodules for MDI forms

I'm creating a new instance of the datamodule whenever an MDI form
that has data controls is created. This ensures each form has their
own view of the data.

Here's the question. Should the datasource be on the form, or in the
data module? In Cantu's Mastering Delphi 5 book he has the Datasource
in the data module (p 456) and then loops through each TDBEdit and
assigns its Datasource to DM.Datasource. This seems like a lot of
work.

Why not just have a Datasource on the form and after creating the data
module, just have "Datasource.Dataset := DM.Table1;". Wouldn't this be
easier? Is there a drawback to doing it this way?

Barry...
--

Barry McClure

<barry_mccl...@grebarsys.com>

 

Re:Question about instantiating datamodules for MDI forms


Hi,

as my understanding of the TDatasource is that it is the interface between
visual and data-based components I place it on the form. It is something
like an anchor of the data-aware form and can be connected to different
datasets if needed.

You can use the form to visualize data from different datasets by simply
changing ONE property.
Additionally I am building an application that should be client/server and
Midas based. When compiling a compiler option tells Delphi to compile one of
the two variants. Also in this case I have to work on a single statement
only.

For example put thi in the Create method of the form :
...
{$IFDEF midas}
DataSource.Dataset := MidasDatamodule.ClientDataset;
{$ELSE}
DataSource.DataSet := ClientServerDataModule.Query;
{$ENDIF}
DataSource.Dataset.Active := TRUE;
...

On the other side I do not see any advantage in putting it into the
datamodule, especially if you do it at runtime.

Quote
>Should the datasource be on the form, or in the data module?
>In Cantu's Mastering Delphi 5 book he has the Datasource in
>the data module (p 456) and then loops through each TDBEdit and
>assigns its Datasource to DM.Datasource. This seems like a lot of work.

This seems quite absurd to me as it makes Datasource become useless and it
will not work for other data-aware components.

Andreas Oberhofer

Re:Question about instantiating datamodules for MDI forms


In article <orrhss4b8nkrjup66ej5v0lgdj2in9s...@4ax.com>, Barry McClure
wrote:

Quote
> Should the datasource be on the form, or in the
> data module?

For me, it depends on the use being made of the datasource. If being used
as part of a master/detail link then I would put it in the datamodule.
When linking data-aware controls, then I place it on the form.
Occasionally I have both needs and then I have two datasources.

 Mike Orriss (TeamB & Developer Express)
 (Unless stated otherwise, my replies relate to Delphi 5)
 (No unsolicited e-mail replies please)

Re:Question about instantiating datamodules for MDI forms


Hello,

Quote
>If being used as part of a master/detail link then I would put it in the
datamodule.
>When linking data-aware controls, then I place it on the form.
>Occasionally I have both needs and then I have two datasources.

I did not want to go that far in my posting otherwise it would have been
even longer...
But the master-detail case is exactly the one (and only) situation where I
use a second Datasource in the datamodule too.

This leads me to the question:
Why do master-detail relations need a Datasource as they are always linked
to a TDataset descendand ?
Having a MasterDataset instead of a MasterSource would help keep the
datamodule simple.

Andreas Oberhofer

Other Threads