Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 13 of 13 total
Thread Application goes to "not responding" for larger queries
Mon, Aug 12 2013 12:06 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Barry


>OK who mentioned putting tables in the datamodule Smile
>
>You can still put the TEDBTable, TEDBQuery and TDatasource on each form. But the thread still needs its own instantiated datamodule that contains the TEDBDatabase, TEDBEngine, TEDBSession.

Wrong! There is no requirement for a datamodule. I have a number of threads and not one of them uses a datamodule eg

type
TAlarmChecker = class(TThread)
private
 iSignal: TSimpleEvent;
 iUserID: string;
 iReportBack: HWND;
 iMsgNo: integer;
 iCrashMsg: integer;
 iNewEMailsMsg: integer;
 iEMailSkipMsg: integer;
 iSession: TEDBSession;
 iDatabase: TEDBDatabase;
 iUnreadEmails: TEDBQuery;
 iNewEmails: TEDBQuery;
 iLastEMail: integer;
 iIsAlarmWanted: TEDBQuery;
 iLTCAlarm: TEDBQuery;
 iCurrentCheck: integer;
 iSkippedEMails: TEDBQuery;
 iLastSkipped: integer;
 FBlinkEMail: boolean;
 FBlinkAlarms: boolean;
 FBlinkLTC: boolean;

constructor TAlarmChecker.Create(const AlarmsParams: TAlarmParams);
begin
inherited Create(True);
iLastSkipped := 0;
FBlinkEMail := False;
FBlinkAlarms := False;
FBlinkLTC := False;
iReportBack := AlarmsParams.ReportBack;
iMsgNo := AlarmsParams.MsgNo;
iCurrentCheck := AlarmsParams.CurrentCheck;
iCrashMsg := AlarmsParams.CrashMsg;
iNewEMailsMsg := AlarmsParams.NewEMailsMsg;
iEMailSkipMsg := AlarmsParams.EMailSkipMsg;
iSignal := TSimpleEvent.Create;
iUserID := AlarmsParams.UserID;
iSession := TEDBSession.Create(nil);
iSession.AutoSessionName := False;
iSession.Name := 'alarm' + IntToStr(ThreadID);
iSession.SessionName := iSession.Name;
iSession.LoginUser := iUserID;
iSession.LoginPassword := AlarmsParams.Password;
iSession.LocalTempTablesPath := AlarmsParams.TempPath;
iSession.LocalEncryptionPassword := AlarmsParams.Encryption;
iSession.LocalConfigPath := AlarmsParams.ConfigPath;
iSession.Connected := True;
iDatabase := TEDBDatabase.Create(nil);
iDatabase.Database := AlarmsParams.Database;
iDatabase.Name := 'alarmDB' + IntToStr(ThreadID);
iDatabase.DatabaseName := iDatabase.Name;
iDatabase.SessionName := iSession.SessionName;
PrepSkippedCheck;
PrepAnyNewEMails;
PrepEMailAlarm;
PrepProjectAlarm;
PrepLTCAlarm;
try
 iDatabase.Execute('DELETE FROM LastCalls WHERE (_Date - CURRENT_DATE) DAY > 90');
except
end;
FreeOnTerminate := True;
Resume;
end;
Mon, Aug 12 2013 5:06 PMPermanent Link

Barry

Roy,

>Wrong! There is no requirement for a datamodule. I have a number of threads and not one of them uses a datamodule<

Yes, you can do it that way. I stand corrected. Smile

It means initializing and instantiating all of the database, session, and engine components individually when each database related form is created. This will work fine for small applications with one form.

Since I have events defined for some of these components and error reporting, I just find it easier to maintain the code in one central location, namely the data module.

But both scenarios will work fine.

Barry
You say "tomato" and I say "tomAto".
Mon, Aug 12 2013 5:45 PMPermanent Link

Raul

Team Elevate Team Elevate


Not necessarily - Delphi object inheritance is a very powerful feature
so I have a base thread class with all the components and creating a DB
thread is as simple as inheriting from our class. We also use
datamodules and those are useful as well. Nice to have a choice Smile

One thing to add is that engine is a singleton so all instances of the
engine component refer to same app level engine. Hence I personally do
not use engine in datamodules at all to avoid any chance of accidentally
changing any settings that affect the app.

Raul

On 8/12/2013 5:06 PM, Barry wrote:
>
> It means initializing and instantiating all of the database, session, and engine components individually when each database related form is created. This will work fine for small applications with one form.
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image