The primary data type you use in day-to-day code is the variant. This is the native, dynamically-typed data of JavaScript. Think of a variant as a universal container: one moment it can hold an integer, the next a string, and then a complex object.


var MyVar: variant;

MyVar := 10;       // MyVar now holds a Number

MyVar := 'Hello';  // MyVar now holds a String


This flexibility is powerful but comes at a performance cost. This "untyped" approach is not efficient for handling large, structured blocks of raw data, like the bytes of an image file or a network packet.

The Typed World: Binary Data (Buffers and Bytes)


The second world is that of binary data. This data is "typed" in the strictest sense: it is a raw, fixed-size block of memory, often represented as a JArrayBuffer or an array of bytes (TUInt8Array). Think of this as a long strip of tiny, numbered boxes, with each box holding just one byte (a number from 0-255). This block of data has no inherent meaning on its own. It's up to you to interpret it. For example, the exact same 4 bytes in memory could represent:


  • A single 32-bit integer.
  • Four individual 8-bit characters.
  • A 32-bit floating-point number.


While standard JavaScript variables are flexible, they are inefficient for this kind of work. To achieve native performance, we must operate on data in its raw, binary form.


In the Quartex RTL the TDataTypeConverter class is a powerful tool for bridging these two worlds, allowing easy converting between typed and untyped data (raw bytes). Then, we will look at TManagedMemory, the class that lets you take direct, low-level control of memory blocks.