CodeRunner Documentation

CodeRunner Built-in Constants

CodeRunner only introduces one additional constant besides what you can read in the MP Language (tutorial.modernpascal.com) section of our servers. The compiler definition CODERUNNER. This allows you to write code that can be executed at the command line, versus behind CodeRunner. Like this example:

Program Example.101;

{$IFNDEF CODERUNNER}
Type
   TSession = Class
      Connected:Private Function:Boolean of Object;
      Writeln:Private Procedure(S:String) of Object;
      Free:Private Procedure of Object;
   End;

Function TSession.Connected:Boolean;
Begin
   Result:=True;
End;

Procedure TSession.Writeln(S:String);
Begin
   System.Writeln(S);
End;

Procedure TSession.Free;
Begin
End;

Procedure TSession.Init;
Begin
   With Self do begin
      // Manually Stitch RTTI Together:
      TMethod(@Connected):=[@TSession.Connected, @Self];
      TMethod(@Writeln):=[@TSession.Writeln, @Self];
      TMethod(@Free):=[TSession.Free, @Self];
   End;
End;

Var
   Session:TSession;
{$ENDIF}

Begin
{$IFNDEF CODERUNNER}
   Session.Init; // CodeRunner Did this already for you!
{$ENDIF}
   While Session.Connected
      Session.Writeln('Hello World!');
      Break;
   End;
{$IFNDEF CODERUNNER}
   Session.Free; // CodeRunner Does this already for you!
{$ENDIF}
End.

That code there will run locally or during the OnConnect session of CodeRunner.