DelphiFAQ Home Search:

Thread-safe and not threadsafe functions in Delphi

 

comments2 comments. Current rating: 4 stars (1 votes). Leave comments and/ or rate it.

Question:

Some Delphi functions, like format, strToDate, ... have two versions : one that is not thread-safe, and another one (with a TFormatSettings parameter) that is thread-safe.

Is there a way to forbid the use of the not thread-safe functions?

Answer:

While there is no known list of all functions that are not thread-safe, you can start building such a list and disable them by defining global constants as shown below.

With these definitions, you can still call System.Append() if you really want to and know what you're doing, but it prevents the casual use of the function.

// Undefine SYSTEM procedures:
const
  append = 0;
  assign = 0;
  blockread = 0;
  blockwrite = 0;
  chdir = 0;
  close = 0;

Comments:

2006-05-10, 10:24:03
anonymous from Australia  
rating
Good idea... We just need to work out what's safe and what's not <sigh>
2006-11-18, 20:21:37
anonymous from China  
Well I think this's code is very safe!

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.