If you come from a traditional Object Pascal background, you're used to a very strict, structured way of defining data. This is one of the language's greatest strengths: it's safe, predictable, and easy to read. In classic Pascal, you must first define a "blueprint" (a type) before you can create an instance of it. This is always done in a type block, completely separate from your application's logic:


// You MUST define the blueprint first

type

 TMyData = record

   first: int32;

   second: string;

 end;


// Then, you can create an instance of it

var

 a: TMyData;

begin

 a.first := 12;

 a.second := 'hello world';

end;


This is a rigid two-step process that have served Pascal developers for decades


Quartex Pascal adds a more flexible, modern feature called anonymous records. This feature, inherited from the DWScript dialect, allows you to define a record structure and create an instance of it at the same time, right in your var block.


var a := record

 first: int32 := 12;

 second: string := "hello world";

end;


Notice what's happening:


  • There is no type block. The record is being defined inline where the variable a is declared.
  • The := operator tells the compiler to infer the type from the structure on the right.
  • The variable a now holds a record with two fields, first and second, which are even pre-initialized.


This structure is called "anonymous" because it doesn't have a formal type name like TMyData. The variable a is the one-and-only instance of this specific, unnamed record structure.



This feature is not just a syntax shortcut; it's a powerful tool for bridging the gap between Object Pascal and JavaScript.


  • In JavaScript, creating an ad-hoc "record" is the most common way to group data. This is known as an object literal.
  • Your anonymous record in Quartex Pascal is the type-safe way to create a plain JavaScript object. It compiles almost 1-to-1.


What you write in Pascal:


var a := record

 first: int32 := 12;

 second: string := "hello world";

end;


Is translated verbatim to JavaScript:


var a = {

 first: 12,

 second: "hello world"

};


This is the same conceptual goal as the "Anonymous objects" feature (which uses the class keyword instead of record) described in the documentation . Both are designed to let you quickly create the simple, plain objects that are so common in the JavaScript world. For a traditional Pascal developer, the benefit is clear: flexibility. You no longer need to pollute your unit's type section with dozens of small, single-use TMyRecordA, TMyRecordB, TMyRecordC definitions.


Anonymous records are perfect for:


  • Creating ad-hoc data structures to pass as parameters.
  • Building JSON objects on the fly.
  • Grouping related variables in your logic without the ceremony of a formal type declaration.