title: Thread-safe way to increment and return an integer in Delphi
body: <p>In a single-threaded application I use code like this:</p>
  
  <pre><code>Interface
      function GetNextUID : integer;
  Implementation
      function GetNextUID : integer;
      const
        cUID : integer = 0;
      begin
        inc( cUID );
        result := cUID;
      end;
  </code></pre>
  
  <p>This could of course be implemented as a singleton object, etc. - I'm just giving the simplest possible example. </p>
  
  <p>Q: How can I modify this function (or design a class) to achieve the same result safely from concurrent threads?</p>