title: AtomicExchange for records in Delphi
body: <p>AtomicExchange requires an Integer or NativeInt variable. So how should I set a value of a record in a thread-safe way?</p>
  
  <p>The record in question looks like this in principle (it has more convenience functions and properties as well in reality):</p>
  
  <pre><code>  TStatusCode = record
    private
      FValue: Cardinal;
    public
      constructor Create(AValue: Cardinal);
      class operator Equal(Left, Right : TStatusCode): Boolean;
      class operator Implicit(Value: TStatusCode): Cardinal;
      class operator Implicit(Value: Cardinal): TStatusCode;
      class operator NotEqual(Left, Right : TStatusCode): Boolean;
      property Value: Cardinal read FValue;
    end;
  </code></pre>