Solved

How to replicate a delphi DATAMODULE at RUNTIME

Posted on 2006-06-17
3
1,270 Views
Last Modified: 2011-10-03
I am using delphi 7 and INDY HTTPSERVER. Database is firebird. Environment is multithreaded.

At DESIGN TIME, i created a DATAMODULE that contains a TSESSION (autonaming is ON), queries and stored procedures.

At RUNTIME, how do I replicate that DATAMODULE (created at design time) for EVERY http client access? Do I use the repository?  If the datamodule is replicated, will it create NEW UNIQUE TSESSION names and replace the session names on all db components in the newly created datamodule?
Explanation and code will be of help, TY.

0
Comment
Question by:syndman
3 Comments
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 25 total points
ID: 16927509
just create the DataModule at runtime on each request, instead of design time

dataModule:TDatamodule.Create(nil);

//be sure to free the datamodule when the the request is done
dataModule.Free;
0
 

Author Comment

by:syndman
ID: 16927572
That datamodule I created at design time contains a lot of components already such as queries and stored procedures. It also has a TSESSION component in it.  If I create that datamodule in runtime, that would mean that I would create again, programmatically, all those components inside the new datamodule. And also, that would mean that I will spend more programming time recreating those components.

Could I use that datamodule I already created in design time so that I would not need to recreate all those components again programmatically for runtime purposes (and I would be able to save time)?  
Thanks
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 25 total points
ID: 16931622
If you are inheriting from the TIdHTTPSession, you can just point it to your current datamodule
Just be aware, that if you are sharing components inside threads (which this will do)
Query1, Table1, etc might be in use, and you could run into trouble if 2 threads want to use the same component

type
  TMyHTTPSession = class(TIdHTTPSession)
  public
    WorkerDataModule:TMyDataModule;
  end;

procedure TForm1.IdHTTPServer1CreateSession(ASender: TIdContext; var VHTTPSession: TIdHTTPSession);
begin
    VHTTPSession := TMyHTTPSession.Create(IdHTTPServer1.SessionList);
    (VHTTPSession as TMyHTTPSession).WorkerDataModule := DataModule1;
end;

from that point on, you just say "WorkerDataModule.Table1....." etc

If you had wanted to create your own datamodule, you could do it at the same point

procedure TForm1.IdHTTPServer1CreateSession(ASender: TIdContext; var VHTTPSession: TIdHTTPSession);
begin
    VHTTPSession := TMyHTTPSession.Create(IdHTTPServer1.SessionList);
    (VHTTPSession as TMyHTTPSession).WorkerDataModule := := TDataModule1.Create(nil); // remember to free it later
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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