4D v14.3

METHOD SET CODE

Home

 
4D v14.3
METHOD SET CODE

METHOD SET CODE 


 

METHOD SET CODE ( path ; code {; *} ) 
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)
Operator in 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. This command can access the code of all types of methods: database methods, triggers, project methods, form methods and object methods.

In the case of a project method: if this method already exists in the database, its contents are replaced; if it does not exist, it is created with its contents. 

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. . 

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.

Concerning the "folder" property of the metadata:

  • When this property is present and corresponds to a valid folder, the method is placed in its parent folder,
  • If this property is not present or if the folder does not exist, the command makes no changes at the parent folder level,
  • When this property contains an empty string, the method is placed at the root level.

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

Example  

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)

 
PROPERTIES 

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

 
HISTORY 

New
Created: 4D v13
Modified: 4D v14

 
SEE ALSO 

METHOD GET CODE

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : METHOD SET CODE ( 4D v13.5)