title: How use bit/bit-operator to control object state?
body: <p>I want to create light object data-package to pass between client and server applications.</p>
  
  <p>It is a so simple task, that I can control with only 1 byte, so
  each bit in a byte will have a different meaning, </p>
  
  <p>Using only the bit</p>
  
  <pre><code>0 = False 
  1 = True
  </code></pre>
  
  <p>Itens I need now:</p>
  
  <pre><code>1 - Loaded from database 
  2 - Persisted
  3 - Changed
  4 - Marked to Delete
  5 -
  6 - 
  7 - Null Value 
  8 - Read Only
  
  
  1) How do I use bit operators in Delphi to check each bit value? 
  2) How do I set the bit Values?
  </code></pre>
  
  <p><strong>Solution</strong></p>
  
  <p>After all help, Ill use the next Set</p>
  
  <pre><code>  TStateType = (
      stLoaded    = 0,   // loaded from persistance
      stNative    = 2,   // value loaded and converted to native type
      stPersisted = 3,   // saved
      stChanged   = 4,   // object or member changed
      stToDelete  = 5,   // marked to delete
      stReadOnly  = 6,   // read only object, will not allow changes
      stNull      = 7    // value is null
    );
    TState = Set of TStateType;
  </code></pre>
  
  <p>And for stream -> persistance, this will be the record to be used:</p>
  
  <pre><code>  TDataPackage = record
      Data: TBytes;
      TypeInfo: TMetaInfo;
      State: Byte;
      Instance: TBuffer;
    end;
  </code></pre>
  
  <p><strong>Thank you</strong> guys, for all the answers and comments.</p>