Solved

How to replicate a delphi DATAMODULE at RUNTIME

Posted on 2006-06-17
3
1,244 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now