This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20 R7
METHOD GET CODE
|
METHOD GET CODE ( path ; code {; option} {; *} ) | ||||||||
Parameter | Type | Description | ||||||
path | Text, Text array |
![]() |
Text or Text array containing one or more method path(s) | |||||
code | Text, Text array |
![]() |
Code of designated method(s) | |||||
option | Longint |
![]() |
0 or omitted = simple export (without tokens), 1 = export with tokens | |||||
* | Operator |
![]() |
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, class definitions, 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:
// %attributes = {"lang":"en","invisible":true,"folder":"Web3"}
The option parameter allows you to select the code export mode with respect to the tokenized language elements of the method(s):
Tokenized language elements include:
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 code=On Load)
ALL RECORDS([Customer])
End case
If you execute the following code:
C_TEXT($path)
C_TEXT($contents)
$path:=METHOD Get path(Path project method;"simple_init")
METHOD GET CODE($path;$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 code=On Load)
ALL RECORDS([Customer])
End case
If you execute the following code:
C_TEXT($path)
C_TEXT($contents)
$path:=METHOD Get path(Path project method;"simple_init")
METHOD GET CODE($path;$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 code:C388=On Load:K2:1)
ALL RECORDS:C47([Customer:1])
End case
Product: 4D
Theme: Design Object Access
Number:
1190
Created: 4D v13
Modified: 4D v14
Modified: 4D v15
Modified: 4D v15 R4
Modified: 4D v18 R3
4D Language Reference ( 4D v20 R7)