Solved

How to replicate a delphi DATAMODULE at RUNTIME

Posted on 2006-06-17
3
1,281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run video youtube webbrowse 10 86
Magic Software info 18 156
Unique identifier on a terminal server (rdp) 4 85
Get monday of current week where a week always starts on monday 2 38
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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