Equivalent for Delphi's "initialization" section for unit with global method?

I have a (global) standalone method in a unit. Depending on whether the code is executed as part of a library or application different things need to happen. I do not want to check every time when the global method is called whether it is running as part of a library or application. In Delphi I would create a global variable that determines this and initialize it once as part of the units “initialization” section. Is something similar possible in Oxygene?

Sort of. If you have global variables with an initializer they create a class constructor which does this for you, alternatively there’s this hack that works too:

namespace ConsoleApplication437;

interface
{$G+}
uses
  System.Linq;

type
  Program = class
  public
    class method Main(args: array of String): Int32;
  end;

type
  __Global = public partial static class 
  private
  public
    class constructor;
  end;
method Test; empty;

implementation

class constructor __Global;
begin 
  writeLn('hello!');
end;

end.

This will trigger the writeln for the first time you call “Test”, like an initialization.

Carlo, thanks for your prompt reply!