Board index » delphi » Creating multiple instance of Datamodule.

Creating multiple instance of Datamodule.

Quote
Matthew Pascoe wrote in message <6dcm6h$di...@forums.borland.com>...
>I need to create an instance of my datamodule for each new MDI child I
>create. What is the syntax for this and at what stage is it called>

You need to

1.  Create an instance of the datamodule.
2.  Create the MDI Child form.
3.  Set the datamodule's name property to ''.

The reason for this:

The second (and additional) instances of the DM have their names suffixed so
they don't duplicate the first datamodule's name.
Forms connect to the datamodule by name, so they always connect to the first
instances, the one with the unmodified name.
Setting the name to '' allows the next datamodule to create with an
unsuffixed name, so the form connects to it.

 

Re:Creating multiple instance of Datamodule.


I need to create an instance of my datamodule for each new MDI child I
create. What is the syntax for this and at what stage is it called>
Thanks for any help.
Matthew Pascoe.

Re:Creating multiple instance of Datamodule.


Scott,
Thanks for your help.
I have a mixture of autocreate forms and dynamically created forms. I
currently have the datamodule as autocreate. What is the best way to handle
this mixture and still have multiple instances of the datamodule. Or should
I create all forms dynamically? Will this cut the time required to load the
application?

Thanks again.
Matthew Pascoe.

Quote
Scott Samet [TeamB] wrote in message <6dd4vu$e...@forums.borland.com>...

>Matthew Pascoe wrote in message <6dcm6h$di...@forums.borland.com>...

>>I need to create an instance of my datamodule for each new MDI child I
>>create. What is the syntax for this and at what stage is it called>

>You need to

>1.  Create an instance of the datamodule.
>2.  Create the MDI Child form.
>3.  Set the datamodule's name property to ''.

>The reason for this:

>The second (and additional) instances of the DM have their names suffixed
so
>they don't duplicate the first datamodule's name.
>Forms connect to the datamodule by name, so they always connect to the
first
>instances, the one with the unmodified name.
>Setting the name to '' allows the next datamodule to create with an
>unsuffixed name, so the form connects to it.

Re:Creating multiple instance of Datamodule.


Scott,

What do you think about this approach: (it's how I do it)

1.  Create the datamodule normally.

2.  Remove it from the project's Autocreate list.

3. Comment out its instance variable (correct my term
if it's wrong please!) in  the datamodule's unit, i.e.

  //DataModule1: TDataModule1;

4.  Add the datamodule's unit to the uses clause of the
implementation section of the form that is going to create the
instance of the datamodule.

5.  Declare the datamodule object in the private section of the
form that is going to create the instance of the datamodule, i.e.

private
  DataModule1: TDataModule1;

6.  Create and Free the instance of the datamodule
as you would any other form.

This way I don't need to mess around with the datamodule
name and can treat it as I would an instance of any other
form

I am not using MDI but I don't think that matters.

Jim

Quote
Scott Samet [TeamB] wrote:
> Matthew Pascoe wrote in message <6dcm6h$di...@forums.borland.com>...

> >I need to create an instance of my datamodule for each new MDI child I
> >create. What is the syntax for this and at what stage is it called>

> You need to

> 1.  Create an instance of the datamodule.
> 2.  Create the MDI Child form.
> 3.  Set the datamodule's name property to ''.

> The reason for this:

> The second (and additional) instances of the DM have their names suffixed so
> they don't duplicate the first datamodule's name.
> Forms connect to the datamodule by name, so they always connect to the first
> instances, the one with the unmodified name.
> Setting the name to '' allows the next datamodule to create with an
> unsuffixed name, so the form connects to it.

Re:Creating multiple instance of Datamodule.


Scott,

Your solution works very nicely, but I don't quite understand why.  You say the
form links to the first datamodule with an unmodified name, but your third step
says to set the datamodule's name to ''.  That would seem to modify it to me.

If setting it to '' keeps the suffix from being added to the datamodule's name,
how does Delphi know it doesn't have duplicates?

Quote
Scott Samet [TeamB] wrote:
> Matthew Pascoe wrote in message <6dcm6h$di...@forums.borland.com>...

> >I need to create an instance of my datamodule for each new MDI child I
> >create. What is the syntax for this and at what stage is it called>

> You need to

> 1.  Create an instance of the datamodule.
> 2.  Create the MDI Child form.
> 3.  Set the datamodule's name property to ''.

> The reason for this:

> The second (and additional) instances of the DM have their names suffixed so
> they don't duplicate the first datamodule's name.
> Forms connect to the datamodule by name, so they always connect to the first
> instances, the one with the unmodified name.
> Setting the name to '' allows the next datamodule to create with an
> unsuffixed name, so the form connects to it.

Other Threads