Solved

How to replicate a delphi DATAMODULE at RUNTIME

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 159
How to convert wav to mp3 in delphi 9 137
IExtractImage Delphi 14 162
Dev Express grid collapse 2 33
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

11 Experts available now in Live!

Get 1:1 Help Now