The ASM keyword has been recycled to allow for inline blocks of JavaScript. But there are a couple of rules when accessing pascal objects or structures from such ASM snippets. These rules are very important and must be followed.

Accessing variables


All references to pascal-side variables must be prefixed with @. This is to help the compiler to map local names to the compiled names. When a Quartex Pascal unit is compiled, the compiler can change the names depending on your build-configuration. This is especially true when obfuscation is on where names are deliberately shortened and randomized to make reverse-engineering more difficult.


Here is an example of accessing a pascal string variable from an ASM block:


var temp: string;

temp := "hello world";

asm

 console.log(@temp);

end;


Accessing objects or structures


When accessing pascal objects (or structures) from an ASM snippet, the object reference must be boxed, like this:



// Create an anonymous structure

var temp := class

 first: int32 := 12;

 second: string := "hello world";

end;


// Access the int32 field, notice the boxing

asm

 (@temp).first += 12;

end;


// Emit the value (prints out 24)

writeln( temp.first );


The reason the object reference must be boxed, is again to help the compiler have clear boundaries.