Board index » delphi » MDI Application and DataModules

MDI Application and DataModules

I have a MDI application and wish to use a datamodule to store my tables. I
find that if I minimize a form that has reference to a table and open another
form that uses the same table, any change to the table is reflected in both
forms. How do I create anothe instance of the datamodule without getting a
"Name already used in this context" error message
 

Re:MDI Application and DataModules


Store a bookmark when you minimize.

Quote
PSISDInc wrote in message

<1998081412031201.IAA25...@ladder03.news.aol.com>...
Quote
>I have a MDI application and wish to use a datamodule to store my tables. I
>find that if I minimize a form that has reference to a table and open
another
>form that uses the same table, any change to the table is reflected in both
>forms. How do I create anothe instance of the datamodule without getting a
>"Name already used in this context" error message

Re:MDI Application and DataModules


Quote
>Store a bookmark when you minimize.

This will work only if I have posted the data. If the data has not been posted
then I will lose it when the other window changes the data.

There must be a way to create another instance of the data module

Re:MDI Application and DataModules


PSISDInc <psisd...@aol.com> wrote in article
<1998081419111000.PAA29...@ladder01.news.aol.com>...

Quote
> >Store a bookmark when you minimize.

> This will work only if I have posted the data. If the data has not been
posted
> then I will lose it when the other window changes the data.

> There must be a way to create another instance of the data module

There is.  Just treat it as if it was a form, and create it at runtime.
You can create as many as you like this way.  You also have to rename the
datamodule after you create it.

Here's the easiest way:
1. Create your edit form.
2. In your edit form's oncreate handler, have it create the datamodule and
assign the new datamodule's instance to a variable owned by the form.
3. Rename the datamodule. (trust me, you have to do this if you want more
than one.)
4. Free the datamodule when the form is destroyed.

Here's some sample code:

unit Unit1;

interface

uses etc, etc;

type
  TYourForm = class(TForm)
    ...
  private
    AttachedModule: TDataModule;
  public
    ...
  end;

implementation

procedure TYourForm.FormCreate(Sender: TObject);
begin
  AttachedModule := TDataModule.Create(Self);
  AttachedModule.Name := 'WhateverYouWant';
end;

Re:MDI Application and DataModules


What is wrong with putting the TTables on the MDI form? Saves extra work.

David

Quote
PSISDInc wrote in message

<1998081419111000.PAA29...@ladder01.news.aol.com>...
Quote
>>Store a bookmark when you minimize.

>This will work only if I have posted the data. If the data has not been
posted
>then I will lose it when the other window changes the data.

>There must be a way to create another instance of the data module

Other Threads