System.Set.ToInt

From RAD Studio API Documentation
Jump to: navigation, search

C++

int __fastcall ToInt(void) const

Properties

Type Visibility Source Unit Parent
function public sysset.h System Set

Description

Stores bits for each element of the Set and returns and integer that has the same bit set.

Use the ToInt method to store the Set value as an integer that has the same bit set. For example, you can store the Set value in a stream.

Example

To clarify, consider the following example.

#include <System.SysUtils.hpp>
#include <fstream>
 
int main() {
  TVisibilityClasses vis;
  vis << vcProtected <<vcPublished;
 
  { // Store Set in binary format
    std::ofstream cfg("test.cfg", std::ofstream::binary);
    int i = vis.ToInt();
    cfg.write(reinterpret_cast<const char*>(&i), sizeof(i));
  }
 
  { // Read binary stream and initialize set
    std::ifstream cfg("test.cfg", std::ifstream::binary);
    int i;
    cfg.read(reinterpret_cast<char*>(&i), sizeof(int));
    TVisibilityClasses vis2(i);
    
    // Confirm that the two Sets are equal
    assert(vis2 == vis);
  }
}