4D v14.3Writing a method |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
Writing a method
|
Copy selected text to a clipboard | Paste contents of a clipboard at cursor location | |
Windows | Ctrl+Alt+click on clipboard icon | Ctrl+click on clipboard icon |
Ctrl+Alt+clipboard number | Ctrl+clipboard number | |
Mac OS | Cmd+Option+click on clipboard icon | Cmd+click on clipboard icon |
Cmd+Option+clipboard number | Cmd+clipboard number |
You can move the line where the cursor is directly without selecting it first using the Move Lines Up and Move Lines Down commands in the Method menu. You can also do this using the combination Alt/Option + Up Arrow or Down Arrow.
Colored bars instantly show you where lines of code were modified since the method was opened:
The change bars change colors to indicate whether or not the modifications were saved:
The Method editor has an autocomplete function. 4D automatically displays suggestions based on the first few characters typed.
In the example given below, typing the string “cop” causes the display of a blue triangle indicating that several suggestions are available:
Note: When the characters you enter correspond to a single possibility, this suggested value appears grayed out (and is inserted if you hit the Tab key):
--->
If there are several suggestions available, 4D displays them in a pop-up list when you hit the Tab key:
The list is in alphabetical order. Choose the value by double-clicking it or scroll the list using the arrow keys of the keyboard and then hit Enter, Carriage Return or Tab to insert the selected value.
By default, you can also insert a suggested value by hitting one of the following delimiter ( ; : = < [ { keys after selecting a value: the value inserted is then followed by the delimiter, ready for data entry.
+ ( key -->
Note: You can disable the use of delimiters for inserting suggested values on the Methods Page of the User preferences.
You can press the Esc key to close the pop-up list or you can continue typing while it is open. The values suggested in the pop-up list are updated as additional characters are typed.
If the characters typed correspond to different types of objects, the list displays them in their current style. The following types of objects can be displayed:
Note: For practical reasons, you can disable the automatic display of the list of suggestions for constants, local and interprocess variables and/or tables. These options are found on the Methods Page of the User preferences.
The Select Enclosing Block function is used to select the “enclosing block” of the code containing the insertion point. The enclosing block can be defined by:
If a block of text is already selected, the function selects the enclosing block of the next highest level and so on, until the entire method is selected.
Pressing Ctrl+Shift+B (Windows) or Command+Shift+B (Mac OS) enables you to reverse this operation and deselect the last enclosing block selected.
Note: If the insertion point is placed in an If or Else type structure, the enclosing block will be the one containing, respectively, the If or Else statement.
You can double-click to select individual "words". When the item name referenced (command, constant, method, etc.) contains spaces, you can select the whole name (including spaces) by using the Alt/Option + Double-click combination.
Standard keyboard shortcuts to navigate the code are available in 4D’s Method editor.
Note: Under Mac OS, substitute the Command key for the Ctrl key (Windows).
Shortcut | Action |
[Shift]+[right arrow] | Create and enlarge the selection, character by character, to the right, or Reduce the selection, character by character, from the left |
[Shift]+[left arrow] | Reduce the selection, character by character, from the right or Create and enlarge the selection, character by character, to the left |
[Shift]+[down arrow] | Create and enlarge a selection, line by line, from the top to the bottom |
[Shift]+[up arrow] | Create and enlarge a selection, line by line, from the bottom to the top |
[Ctrl]+[Shift]+[right arrow] | Create and enlarge the selection, word by word, from the right |
[Ctrl]+[Shift]+[left arrow] | Reduce the selection, word for word, from the right, or create and enlarge the selection, word by word, from the left |
[Ctrl]+[right arrow] | Move the insertion point, word by word, from left to right |
[Ctrl]+[left arrow] | Move the insertion point, word by word, from right to left |
[Home] | Place the insertion point at the beginning of the line |
[End] | Place the insertion point at the end of the line |
[Ctrl]+[Home] | Place the insertion point at the beginning of the method |
[Ctrl]+Fin | Place the insertion point at the end of the method |
[Shift]+[Home] | Select all the characters in the line that are to the left of the cursor |
[Shift]+[End] | Select all the characters in the line that are to the right of the cursor |
[PgUp] | Scroll the contents of the method, page by page, from the bottom to the top (doesn’t modify the insertion point) |
[PgDn] | Scroll the contents of the method, page by page, from the top to the bottom (doesn’t modify the insertion point) |
4D automatically checks the method syntax to see if it is correct. If you enter text or select a component that is not syntactically correct, 4D displays a symbol to indicate the incorrect expression . When you move the mouse over the symbol, a help tip displays the cause of the error:
When entering code, you can immediately check the syntax of the current line (without advancing to the next line) by pressing the Enter key on the numeric keypad. 4D evaluates the line, formats it, marks any errors, and places the insertion point at the end of the line. When a line of a method is marked as having improper syntax, check and fix the entry. If the line is now correct, 4D removes the error symbol. When you save or close the window, the entire method is validated. You can also force validation by pressing the Enter key.
When the method is validated, 4D checks for basic syntax errors and for the structure of the statements (If, End if and so on). 4D also checks for matching enclosing characters in the code such as parentheses or quotation marks. When you type an enclosing character, 4D indicates the match by framing the start/end characters with gray rectangles:
Note: If you click on an enclosing character in the code, 4D indicates its match with gray rectangles by default. You can modify the way 4D indicates matching enclosing characters or disable this feature by means of the "Matching parentheses" option on the Methods Page of the Preferences.
The Method editor can only check for obvious syntax errors (misspellings and the like). It does not check for errors that only occur during execution. Execution errors are caught by 4D when the method is executed. 4D provides a debugger (see Debugging) for handling and correcting these errors. The compiler also provides indispensable help for detecting errors. For more information about the compiler, refer to the Compilation chapter.
The Method editor provides various contextual information using help tips which appear when you move the mouse over an object.
You can display the HTML documentation of a 4D language command at any time: to do so, select the complete command name or simply place the cursor in the name and press F1. The complete documentation of the command is displayed in a new window of your default browser.
4D looks for the on-line documentation of the command (on the 4D Doc Center site) or searches locally depending on the settings made in the application Preferences (see Documentation location).
Comments are inactive lines of code. These lines are not interpreted by the program (4D does not apply any particular style within comments) and are not executed when the method is called.
To create a comment, you just need to insert the // characters at the beginning of a line.
The length of comments is limited to the maximum size of a line, which is 32,000 characters.
The Comment/Uncomment command, found in the Method menu as well as in the Method editor context menu, is used to mark a group of selected lines of code as comments, or, on the contrary, to remove the comment characters from a selection.
To use this command, select the code to be marked as commented, then select the Comment/Uncomment command:
-->
When the selection contains only active code, the Comment command is applied. When the selection includes both active code and commented lines, an additional pair of comment characters ( // ) is added to the latter; this way, they will retain their initial commented status if the line is subsequently “uncommented.” When the selection contains only commented lines, the Uncomment command is applied.
Note: The Comment/Uncomment command only operates with full lines — it cannot be used to comment only part of a line.
The Method editor allows you to use escape sequences (also called escape characters). An escape sequence is a sequence of characters that can be used to replace a “special” character.
The sequence consists of a backslash \, followed by a character. For instance, \t is an escape sequence for the Tab character. Escape sequences facilitate the entry of special characters: the previous example (\t) replaces the entry "Character(Tab)".
In 4D, the following escape sequences can be used:
Escape sequence | Character replaced |
\n | LF (Line feed) |
\t | HT (Tab) |
\r | CR (Carriage return) |
\\ | \ (Backslash) |
\" | " (Quotation marks) |
Note: It is possible to use either upper or lower case in escape sequences.
In the following example, the Carriage return character (escape sequence \r) is inserted in a statement in order to obtain the dialog box shown:
ALERT("The operation has been completed successfully.\rYou may now disconnect.")
Warning: The \ (backslash) character is used as a separator in pathnames under Windows. In general, 4D will correctly interpret Windows pathnames entered in the Method editor by replacing the single backslash \ with a double backslash \\. For instance, C:\Folder will become C:\\Folder. However, if you write “C:\MyDocuments\New”, 4D will display “C:\\MyDocuments\New”. In this case, the second backslashþis interpreted incorrectly as \N (an existing escape sequence). You must therefore enter a double backslash \\ when you want to have a backslash in front of a character used in one of the escape sequences recognized by 4D.
Several functions in the Method editor make code easier to read and facilitate browsing among the statements.
4D code located inside loops and conditions can now be collapsed or expanded, in order to facilitate the reading of methods:
If you place the mouse over the expand button [...], a help tip appears, displaying the first lines of the hidden code.
A collapsed portion of code can be selected, copied, pasted or deleted. All the lines included therein will be copied, pasted or deleted respectively. When a portion of code is pasted, it is automatically expanded.
There are several ways to expand and collapse code:
Two commands make it easier to move around within code structures (e.g. If...Else...End if):
These commands are found in the Method menu as well as the context menu of the editor. You can also use the following shortcuts:
4D lets you associate bookmarks with certain lines in your methods. You can then browse quickly within the code by passing from one bookmark to another using specific commands.
A bookmark moves along with its original row if additional rows are inserted in the method. Bookmarks are saved with the methods.
Bookmarks are managed using the Bookmarks submenu of the Method menu:
Note: You can use bookmarks as markers for lines that contain an item found by a search. In this case, 4D automatically adds the bookmarks. For more information, refer to Find and replace in methods.
Product: 4D
Theme: Editing methods
IME
4D Design Reference ( 4D v14 R2)
4D Design Reference ( 4D v13.4)
4D Design Reference ( 4D v14 R3)
4D Design Reference ( 4D v14.3)
4D Design Reference ( 4D v14 R4)
Inherited from : Writing a method ( 4D v12.4)