IMPORT

Import a namespace or static class

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
IMPORT namespace

or

IMPORT STATIC type    (.NET only)

Arguments

namespace

A namespace or nested namespace to import.

type

A fully qualified type name (the full namespace name along with the type name) for the class type whose static members you want to reference without specifying a type name.

Discussion

An IMPORT statement imports a namespace or class so you don't have to repeatedly enter a qualified member name or type name, which helps to avoid verbose code.

The first syntax above imports a specified namespace from a prototype file or from another .dbl source file into the current .dbl source file, enabling you to use members of that namespace without having to type the fully qualified member name. A namespace defined in a file is available only to that file unless it is explicitly imported into other files in the compilation unit with IMPORT or, in traditional Synergy, implicitly imported with SYNDEFNS. A namespace imported with IMPORT applies only to the file into which it is imported. If namespace is a nested namespace (for example, MyNamespace.Subnamespace), only the nested namespace is imported (and not the parent namespace). Conversely, a nested namespace is not imported automatically when its parent namespace is imported. Each nested namespace requires its own IMPORT statement.

The second syntax above provides a static import in Synergy .NET, which enables you to use static members of a class (and nested types) in your code without specifying the type name each time.

An IMPORT statement should go at the beginning of the source file, before any other declarations. It cannot occur inside of a namespace declaration.

Note

An implicit main—that is, a PROC statement or a data division construct such as RECORD without the MAIN keyword—cannot immediately follow an IMPORT statement (although it can occur elsewhere in the program or source file). If a main routine immediately follows an IMPORT statement, it must have the keyword MAIN.

See also

Importing a namespace

Examples

The statement below imports members of the Namespace1 namespace to the current file.

import Namespace1

The following example uses static imports.

import static ns1.class1
import static ns1.class1.class2
import static ns1.class4
main
proc
	console.writeline(MYVAL)	; static field
	console.writeline(smeth1())	; static method
	console.writeline(sprop)	; static property
	sprop = 9
	data cvar, @ns1.class1
	console.writeline(cvar.emeth())	; extension method
		
	console.writeline(class2.MYVAL2)
	console.writeline(class2.smeth2())
		
	console.writeline(MYVAL2)
	console.writeline(smeth2())
end

The file that contains the definitions referenced above looks like this:

namespace ns1
    class class1
        public fld1, int, 8
        public const MYVAL, int, 8
        public static method smeth1, int 
        proc
            mreturn 88
        endmethod
        public static readwrite property sprop, int, 888

        public class class2
            public const MYVAL2, int, 9
            public static method smeth2, int
            proc
                mreturn 99
            endmethod
        endclass
    endclass

    class class3
        public const MYVAL, int, 7
        public static method smeth1, int
        proc
            mreturn 77
        endmethod
    endclass

    public static abstract class class4
        public static extension method emeth, int
            parm1, @ns1.class1
        proc
            mreturn 8888
        endmethod
    endclass
endnamespace