This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20 R7
METHOD SET CODE
|
METHOD SET CODE ( path ; code {; *} ) | ||||||||
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) | |||||
* | Operator |
![]() |
If passed = command applies to host database when executed from a component (parameter ignored outside of this context) | |||||
The METHOD SET CODE command modifies the code of the method(s) designated by the path parameter with the contents passed in the code parameter.
The command can access the existing code of all types of methods: database methods, class definitions, triggers, project methods, form methods and object methods.
If a method does not exist, it is created with the code contents.
Note for projects:
You can use two types of syntaxes, based either on text arrays, or text variables:
C_TEXT(tVpath) // text variables
C_TEXT(tVcode)
METHOD SET CODE(tVpath;tVcode) // code of a single method
ARRAY TEXT(arrPaths;0) // text arrays
ARRAY TEXT(arrCodes;0)
METHOD SET CODE(arrPaths;arrCodes) // code of several methods
You cannot mix the two syntaxes.
If you pass an invalid pathname, the command does nothing.
When METHOD SET CODE is called, the method attributes are reset by default. However, if the first line of the method code contains valid metadata (expressed in JSON), they are used to specify the method attributes and the first line is not inserted. Example of metadata:
// %attributes = {"invisible":true,"lang":"fr","folder":"Security"}
Note: These metadata are generated automatically by the METHOD GET CODE command. For more information about supported attributes, refer to the description of the METHOD SET ATTRIBUTES command.
Concerning the "folder" property of the metadata:
You can execute this command from a component, but in this case, you must pass the * parameter because access to the component code is read-only. If you omit the * parameter in this context, the error -9763 is generated.
This example exports and imports all the project methods of an application:
$root_t:=Get 4D folder(Database folder)+"methods"+Folder separator
ARRAY TEXT($fileNames_at;0)
CONFIRM("Import or export methods?";"Import";"Export")
If(OK=1)
DOCUMENT LIST($root_t;$fileNames_at)
For($loop_l;1;Size of array($fileNames_at))
$filename_t:=$fileNames_at{$loop_l}
DOCUMENT TO BLOB($root_t+$filename_t;$blob_x)
METHOD SET CODE($filename_t;BLOB to text($blob_x;UTF8 text without length))
End for
Else
If(Test path name($root_t)#Is a folder)
CREATE FOLDER($root_t;*)
End if
METHOD GET PATHS(Path project method;$fileNames_at)
METHOD GET CODE($fileNames_at;$code_at)
For($loop_l;1;Size of array($fileNames_at))
$filename_t:=$fileNames_at{$loop_l}
SET BLOB SIZE($blob_x;0)
TEXT TO BLOB($code_at{$loop_l};$blob_x;UTF8 text without length)
BLOB TO DOCUMENT($root_t+$filename_t;$blob_x)
End for
End if
SHOW ON DISK($root_t)
Product: 4D
Theme: Design Object Access
Number:
1194
Created: 4D v13
Modified: 4D v14
Modified: 4D v15
Modified: 4D v18 R3
4D Language Reference ( 4D v20 R7)