[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dynamically creating Datamodule

Posted on 1998-10-04
2
Medium Priority
?
559 Views
Last Modified: 2010-04-03
Hi,

I have an application that needs three datamodules, all of the same type.  Each datamodule will have a different connection (username/password) to a common database.

These three datamodules need to be accessible from everywhere, i.e. global.  I have created a datamodule in the IDE, called Oracle_DM1.  I now want to create three "copies" of it.

The problem is that the first one gets created successfully, but the 2nd and the 3rd ones have a value of nil.

Here's the applicable code fragments...

The project source file...

-----------------------------------------------------------------------------------
program DBG;

uses
  Windows,
  SysUtils,
  Forms,
  Main in 'MAIN.PAS' {MainForm},
  Oracle_DataMod1 in 'Oracle_DataMod1.pas' {Oracle_DM1: TDataModule},
// others deleted here
  DataModStuff in 'DataModStuff.pas';

{$R *.RES}  

begin

  Application.CreateForm(TOracle_DM1, Oracle_DM1);  // seems to be OK
  Application.CreateForm(TOracle_DM1, Oracle_DM2);  // gets a value of nil
  Application.CreateForm(TOracle_DM1, Oracle_DM3);  // gets a value of nil
  Application.CreateForm(TMainForm, MainForm);          // Main Form
  Application.Run;
end.

------------------------------------------------------------------------------------------

unit Oracle_DataMod1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, OracleData, OraclewwData, Oracle;

type
  TOracle_DM1 = class(TDataModule)
    OracleSession1: TOracleSession;
    OracleLogon1: TOracleLogon;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Oracle_DM1: TOracle_DM1;
  Oracle_DM2: TOracle_DM1;  // I added this line
  Oracle_DM3: TOracle_DM1;  // I added this line

implementation

{$R *.DFM}

end.

----------------------------------------------------------------------------------------------------------------

Oracle_DM2 and Oracle_DM3 start off as nil but are set to a value when the MainForm.Create is ran. This form has in it's USES clause Oracle_DataMod1.  However, when I access the value of Oracle_DM2, even though the value does exist, or at least the IDE can read it, I get a Read Access Violation, and the app blows up.

I feel that the problem is either in the way I am creating the three data modules or a scoping issue.

Any idea what I am doing wrong? Environment is D3 with NT40

Thanks
0
Comment
Question by:gspears060598
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:pjdb
ID: 1341769
Can you try
Oracle_DM2:=TOracle_DM1.Create(Application);
instead of
Application.CreateForm(TOracle_DM1, Oracle_DM2)

However, you'll have to destroy the object yourself

JDB
0
 
LVL 1

Accepted Solution

by:
RJENKINS earned 100 total points
ID: 1341770
Inherit the second and third DataModules from the original DM
Goto File| New..
and select the tabwith you projects name
thisa will create 3 different Unit files which will have to be saved seperately

Remember only to make changes to the first (original DataModule)
this will keep them in sync

Hope this Helps
RCJ
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question