Main Method

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.



The Main method in an Delphi Prism project is the entry point for that executable (unless an Entry Point exists). Every .NET project that's not a library (.dll) needs one. The main method can be in any class unless the Startup Object setting is set in the Project Options, when it's required to be in that class.


The Main method has to be a class method. It can have an Integer result or no result at all. In the case of an integer result, the value is used as the command line exit code. A Main method can have no parameters or 1 parameter, which can be a string or an array of string, to contain the command line arguments.

class method Program.Main(Args: array of String): Integer;
begin
  if Length(Args) <> 1 then begin
    Console.WriteLine('Filename expected!');
    exit 1;
  end;
  RunWith(Args[0]);
  exit 0;
end;


See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox