Home

TOTVS Technology

Child pages
  • Namespace
Skip to end of metadata
Go to start of metadata

Available in: 17.3.0.0 for TL++ language

The resource of namespace was released in the version 17.3.0.0 and has as benefit the better organization of the code.

The name of the namespace may be a simple name or a name containing "." as separator.


Functions in the namespace:

Example:

exemplo1.tlpp
namespace exemplo

main function testeNamespace
	conout("testeNamespace")
	testeNamespace2() //a função testeNamespace2 can be called neither expliciting the namespace nor with the use of using because they are in the same source
return

function testeNamespace2
	conout("testeNamespace2")
return

To call a function that is declared in the namespace of other source, you must explicit it, the separator used is "." as example below:

exemplo2.tlpp
user function exemplo2
 exemplo.testeNamespace2()
return

Other option to call a function that is declared in the namespace is to use the instruction "using namespace" according this example:

exemplo3.tlpp
using namespace exemplo
user function exemplo3
  testeNamespace2() //in this case, as there is no function with this source, it will execute the function that is in the source exemplo1.tlpp because the namespace example is defined.

Classes in the namespace:

Example:

exemplo4.tlpp
#include "protheus.ch"
namespace exemplo2.1

class ClassWithNamespace
 method new()
 data dataI
endclass
 
 
method new() class ClassWithNamespace
	conout("construtor do ClassWithNamespace no namespace exemplo2")
return self


main function exemplo4()
	local obj := exemplo2.1.ClassWithNamespace():new() //in this case, the namespace is explicit and the object is created from ClassWithNamespace class, which is in the namespace exemplo2
	local obj2 := exemplo.ClassWithNamespace():new() //in this case, the namespace is explicit and the object is created from ClassWithNamespace class, which is in the namespace exemplo
	local obj3 := ClassWithNamespace():new() //in this case, it is not explicit, but there is a class with this hame defined in this source, so this one is used.
return



To use a class that is declared in the namespace of other source, you must explicit it, the separator used is "." as example below:

exemplo5.tlpp
user function exemplo5()
 Local o1 := exemplo2.1.ClassWithNamespace():New()
Return

Other option to use a class declared in the namespace of other source is to use the instruction "using namespace" according to example below:

exemplo6.tlpp
using namespace exemplo2.1
user function exemplo6()
 Local o1 := ClassWithNamespace():New()
Return

  • No labels