4D v16.3

METHOD GET CODE

Home

 
4D v16.3
METHOD GET CODE

METHOD GET CODE 


 

METHOD GET CODE ( path ; code {; option} {; *} )  
Parameter Type   Description
path  Text, Text array in Text or Text array containing one or more method path(s)
code  Text, Text array in Code of designated method(s)
option  Longint in 0 or omitted = simple export (without tokens), 1 = export with tokens
Operator in If passed = command applies to host database when executed from a component (parameter ignored outside of this context)

The METHOD GET CODE command returns, in the code parameter, the contents of the method(s) designated by the path parameter. This command can return the code of all types of methods: database methods, triggers, project methods, form methods and object methods.

You can use two types of syntaxes, based either on text arrays, or text variables:

 C_TEXT(tVpath// text variables
 C_TEXT(tVcode)
 METHOD GET CODE(tVpath;tVcode) // code of a single method

 ARRAY TEXT(arrPaths;0) // text arrays
 ARRAY TEXT(arrCodes;0)
 METHOD GET CODE(arrPaths;arrCodes) // code of several methods

You cannot mix the two syntaxes.

If you pass an invalid pathname, the code parameter is left empty and an error is generated. 

In the text of the code generated by this command:

  • Command names are written in English for all versions of 4D, except when you use a French version and check the "Use regional system settings" preference (see Methods Page). When you use the option parameter, the code can contain language tokens in order to make it independent from the 4D programming language and version (see below).
  • To increase code readability, text is indented with tab characters based on programming structures, like in the Method editor.
  • A line is added in the header of the code generated containing metadata used when importing code, for example:
      // %attributes = {"lang":"en","invisible":true,"folder":"Web3"}

    During an import, this line is not imported, it is only used to set the corresponding attributes (attributes that are not specified are reset to their default value). The "lang" attribute sets the export language and prevents an import into an application in a different language (in this case, an error is generated). The "folder" attribute contains the name of the method’s parent folder; it is not shown when the method does not have a parent folder.
    Additional attributes can be defined. For more information, refer to the description of the METHOD SET ATTRIBUTES command.

The option parameter allows you to select the code export mode with respect to the tokenized language elements of the method(s):

  • If you pass 0 or omit the option parameter, the method code is exported without tokens, i.e. just like it is displayed in the Method editor.
  • If you pass 1 or the Code with tokens constant, the method code is exported with tokens, i.e. tokenized elements are followed by their internal reference in the code exported contents. For example, the expression "String(a)" is exported "String:C10(a)", where "C10" is the internal reference of the String command.

Tokenized language elements include:

  • 4D commands and constants,
  • Table and field names,
  • 4D plug-in commands.

Code exported with tokens is independent from any subsequent renaming of language elements. Thanks to tokens, code provided as text will always be interpreted correctly by 4D, whether by means of the METHOD SET CODE command or even by copy/paste. For more information about the syntax of 4D tokens, please refer to Using tokens in formulas.

If the command is executed from a component, it applies by default to the component methods. If you pass the * parameter, it accesses the methods of the host database.

Refer to the example of the METHOD SET CODE command.

This example illustrates the effect of the option parameter.

You want to export the following "simple_init" method:

 Case of
    :(Form event=On Load)
       ALL RECORDS([Customer])
 End case

If you execute the following code:

 C_TEXT($code)
 C_TEXT($contents)
 $code:=METHOD Get path(Path project method;"simple_init")
 METHOD GET CODE($code;$contents;0) //no tokens
 TEXT TO DOCUMENT("simple_init.txt";$contents)

The resulting document will contain:

  //%attributes = {"lang":"en"} comment added and reserved by 4D
Case of
    : (Form event=On Load)
        ALL RECORDS([Customer])
End case

If you execute the following code:

 C_TEXT($code)
 C_TEXT($contents)
 $code:=METHOD Get path(Path project method;"simple_init")
 METHOD GET CODE($code;$contents;Code with tokens//use tokens
 TEXT TO DOCUMENT("simple_init.txt";$contents)

The resulting document will contain:

  //%attributes = {"lang":"en"} comment added and reserved by 4D
Case of
    : (Form event:C388=On Load:K2:1)
        ALL RECORDS:C47([Customer:1])
End case



See also 

METHOD SET CODE
Using tokens in formulas

 
PROPERTIES 

Product: 4D
Theme: Design Object Access
Number: 1190

 
HISTORY 

Created: 4D v13
Modified: 4D v14
Modified: 4D v15
Modified: 4D v15 R4

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)