Jump to content

Thread safe using Database objects from main module in standard delphi unit


albertovesx

Recommended Posts

Hi, is it thread safe to add a standard Delphi Unit to use database manipulation functions with object from mainmodule?

for example:
 

function getInformation(DataSet: TuniQuery): Boolean;
begin
  // do something
end;

//call it like this

 if getInformation(MainModule.qryPerson) then
  // do something

 

 

Link to comment
Share on other sites

  • albertovesx changed the title to Thread safe using Database objects from main module in standard delphi unit
On 2/8/2022 at 8:39 PM, albertovesx said:

Hi, is it thread safe to add a standard Delphi Unit to use database manipulation functions with object from mainmodule?

for example:
 

function getInformation(DataSet: TuniQuery): Boolean;
begin
  // do something
end;

//call it like this

 if getInformation(MainModule.qryPerson) then
  // do something

 

 

Good question.

IMHO, No it's not safe.

A classical vcl Unit, is like a static model, witch will be view by all sessions.

How can you garantee that a DataSet sended by a session, matches the correct session ?

So, for this reason it's desirable and  advisable to use UniDataModule.

Even better : you can create a class on a UniDataModule and work with object on UniFrame or UniForm.

Obj.myDataSet:=Query1;

If obj.fct_GetInformation then...

 

Related topic:

http://forums.unigui.com/index.php?/topic/11974-global-variable/&do=findComment&comment=63879

 

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...