Jump to content

is a standard Delphi Unit thead safe ?


Abaksoft

Recommended Posts

Hi all,

I want to use an UniFrame with controls, and write its business logic on a seaparate unit (add a standard Delphi Unit) let's say Ucode.pas

 

This technic allows to write code ones (same base code) for desktop and mobile (just add an other UniFrame for mobile and use the same Unit Ucode.pas)

 

1- Is it a good way ?

2- In other word is a standard Unit thread safe ?

3- Can i use instead an UniDataModule ?

4- Is it a plane to integate an UniUnit (thread safe) ?

Thx.

Link to comment
Share on other sites

  • Administrators

You can use a DataModule created from uniGUI wizard.

 

Write your business logic in this DataModule and share it among mobile and desktop.

 

As long as you don't use global variables your code is thread-safe provided that you don't use any third-party component which is not thread-safe.

Link to comment
Share on other sites

Hi Farshad! Is it safe to declare a variable in mainmodule that I would be using to hold like a username during the session life? My understanding is that the variable will be unique for each session! Thanks Sokel

Link to comment
Share on other sites

Hi sokel,

yes :

- MainModule and UniDataModule are Client side (Target each cession).

- ServerModule is Server side. It's dangerous and forbidden to declare a public variable on serverModule.

 

In public section of MainModule, your variable will be global for one thread (1 cession). That's the correct way.

Link to comment
Share on other sites

In my knowledge : Yes the two are possible.

1. If you declare it in a global unit (standard Delphi Unit) the constant is the same for all clients (sessions).

 

2. If you declare it in an UniDataModule or MainModule your constant will be viewed only by one client (its session).

 

Regards...

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...