I'm tasked with maintaining a very old Delphi XE7, IntraWeb 14 (I think.. how do I determine the IW version number installed?), OS: Windows Server 2008

The IntraWeb app is working well. It connects to a Firebird database and all the DB connection components (DAC by DevArt version 5.5.16) are in the UserSessionUnit.

My task is to allow this old app to connect to an additional Firebird database. The company is upgrading all their apps, and they all point to a new Firebird database that has a different internal table and field structure (both "old" and "new" DBs are Firebird 3x, just different tables and fields). The Intraweb app is a "helper" app, not the main one, so it must be made to bridge the gap between old and new.

I've done this before, many years ago, but forgot the best way to code this. Here is my plan:

- Leave everything that is working, alone
- With your generous help, code the few lines in the few places necessary, to create an additional datamodule for the user session.
- Copy everything from the existing working UserSessionUnit to the newly created-on-the-fly datamodule (All component names can remain the same this way, making other code adjustments easier. Only the datamodule the components and code point to, need be changed.)
- In the .ini file, put a flag that tells the IntraWeb app to use the old DB or the new one. (I'll flip this on "switch over" day from old DB to new DB)- Make adjustments in the code to point to the appropriate datamodule and thereby the appropriate DB as indicated by the parameter in the above step

Question:

- I need step by step instructions on how to add an additional data module to the IW / Delphi XE7 app, starting right from the menus in XE7, to the final coding snippets and tell me the units to put them in.

First thing you need to do is moving the var DataModule1 created by Delphi IDE to the implementation section and change it into a threadvar, so each session gets its own copy. You also change the name (I just added an underscore to it)

Then you declare a function named DataModule1 which will create an instance on demand. The owner of the new data module instance becomes the WebApplication instance which means that you don't need to worry about its destruction (WebApplication will do it for you).

And that's it. You can start using it as you would in any other Delphi application just using its name "DataModule1" to reference it and everything will just work.

PS: There are several ways of achieving the same result, but I find this way particularly handy and easy to understand.

First thing you need to do is moving the var DataModule1 created by Delphi IDE to the implementation section and change it into a threadvar, so each session gets its own copy. You also change the name (I just added an underscore to it)

Then you declare a function named DataModule1 which will create an instance on demand. The owner of the new data module instance becomes the WebApplication instance which means that you don't need to worry about its destruction (WebApplication will do it for you).

And that's it. You can start using it as you would in any other Delphi application just using its name "DataModule1" to reference it and everything will just work.

PS: There are several ways of achieving the same result, but I find this way particularly handy and easy to understand.

Alexandre, I understood from original question He needs to create a datamodule attached to User Session. In your code the datamodule owner is WebApplication not UserSession.
Is it correct?