But this is, sadly, impossible - it will cause runtime access violations!
You can never add a tDataModule to a tWebModule application.
In other words, you can never port an application with a tDataModule to a
ISAPI webserver with the tDataModule intact. WHAT!?!
Borland's solution in the help file: Merge your code in the two modules. No
module can coexist with a tWebModule.
This really came as a surprise to me, as you can have as many tDataModules
coexisting in an application.
I am not ready to start merging the two modules into one, since the
tDataModule belongs in the old project as well,
and simply cannot come to terms with having to make two copies of the
module. Similar maintainance in two modules is bad style.
So here comes the question,
does anybody know of a different option?
Would it suffice to encapsulate the tDataModule in a separate .DLL project
and then let the ISAPI webserver access that library?
Or is coexistence really impossible?
Kind regards,
Christian Loft
There is no such limitation, you can freely use datamodules in a web
application.
What the issue is that you are running into is the fact that a web
module is, by definition, multi-threaded, and different threads cannot
safely access the same datamodule (or the same anything else) at the
same time. Do not autocreate your datamodule(s). Instead, when you
handle an action in your webmodule you must decide which of the
datamodules you need to service that request and create an instance of
them then (and free them at the end of the action - best done in a try /
finally block).
--
Wayne Niddery (WinWright Inc.)
RADBooks - http://members.home.net/wniddery/RADBooks/delphibooks.html
"At the apex of every great tragedy of mankind there stands the figure
of an incorruptible altruist" - Ayn Rand
I've an ISAPI app the has both a TWebModule and TDataModule. However I did
hit a problem when we first started developing but this was due to the
TDataModule being autocreated, or being created within the initialization
section of a pas file. Once this was removed and dynamically created as and
when needed we've had no problems since.
>Do not autocreate your datamodule(s). ??
An instance of the tDataModule per tWebModule action is, of course,
necessary for data integrity, now that I think of it.
My only grudge now is that my tDataModule contains 16 tables, which are all
needed for the action.
Thus, instantiating the module takes time,
and the multiple instantiations will lay claims on db connections and
memory.
But this was to be expected, I guess.
Now I know where to go.
Kind regards,
Christian Loft
"Wayne Niddery (TeamB)" <winw...@chaffhome.com> wrote in message
news:3abfc4d8$1_2@dnews...
I have changed my code but still get the exception "Only one datamodule per
application".
I am now only creating the tWebModule in the project source.
The webmodule has an action which looks like this:
procedure TWebModule1.WebModule1ProcessAction(Sender: TObject; Request:
TWebRequest; Response: TWebResponse; var Handled: Boolean);
var Data : tdata; // <----- this is my tDataModule object
begin
//Handling Request fields.. not shown here
Data := tData.Create(self);
//Process data.... not shown here
//Handling Response content ... not shown here
Data.free;
end;
This is wrong, I gather..
But how is it wrong?
Best regards,
Christian
"Andrew Watts" <andrew...@xenicom.com> wrote in message
news:3ac043f1_1@dnews...
There is strategy to overcome this - create your DM in WebModuleCreate
and free it in WebModuleDestroy.
>and the multiple instantiations will lay claims on db connections and
>memory.
>But this was to be expected, I guess.
Connection object (TDatabase, TADOConnection, ...) could be passed to DM
initialization for reuse.
Also, there is a way to reuse DM in a web application with a visual form
inheritance: create new WebBroker project, add DM unit to project,
create new unit that inherits from DM and add TWebDispatcher to it - now
we have main module where new web actions can be defined. In this setup
all DB specific stuff goes to ancestor (original DM) , WebBroker
specific stuff goes to derived module.
---
Danilo Cuculic
Regards,
Michael
Data := tData.Create(nil);
---
Danilo Cuculic
Best regards,
Christian Loft
"Danilo Cuculic" <dan...@spamblock-techie.com> wrote in message
news:aon0ctotf1os0mj9l...@4ax.com...