Solved

How to replicate a delphi DATAMODULE at RUNTIME

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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