New Statement
Makes an instance of an object and initializes it.
Syntax
[ @Shared ] [ New ] class_name [ type_list ] object_name [ , argument_list ]
[ Begin [ default_type | Call method_name [ initializer ] ]
[ statements ]
End [ New | class_name ] ]
Parts
@Shared
- Optional – There can be only one instance.
New
- Optional keyword.
class_name
- Mandatory name of a class.
type_list
- Optional – See Type List for more information.
object_name
- Mandatory name for the object.
argument_list
- Optional – One or more expressions with a comma between each.
Begin
- Optional start of the block construct.
default_type
- Optional data type that the compiler will use for the subsequent statements, if the data type is not specified.
The data type must be related to the type specified in a constructor of
class_name
. method_name
- Optional name of the method to call for each
initializer
orstatement
. It must come after the keywordCall
. initializer
- Optional on the same line after
method_name
. It must be a list of values with a comma between each, all between braces ({ }
). statements
- Mandatory in the block construct and if there is no initializer, one or more object-creation statements. See the section “Permitted members” for more information.
End
- Completes the block construct.
You can also use one of
End New
orEnd
class_name
.
Instructions
Permitted members
New
Object
- an argument list, which is seen as the arguments to
New
Changes in syntax with @Option
There are two areas where you can change the syntax of the statement:
@Option New With New
and@Option New Without New
@Option End With Block
and@Option End Without Block
See @Option Directive for more information.
Examples
One-line constructs
' Find all text files in the current directory.
Files txtFiles, "*.txt"
' Make a menu.
Menu FileMenu, "&File", "&Open...", DoOpen, |, "E&xit", DoExit
Block constructs
New Menu FileMenu, "&File"
Begin
"&Open...", DoOpen
|----
"E&xit", DoExit
End New
Menu FileMenu, "&File"
Begin
"&Open...", DoOpen
|----
"E&xit", DoExit
End Menu
Call construct
List[String] fruits
Begin Call Add {
"apple", "banana", "cherry"
}
End