Code Completion
Go Up to Getting Started with RAD Studio
Code Completion (Ctrl+Space) is a Code Insight feature available in the Code Editor. Code Completion displays a resizable "hint" window that lists valid elements that you can select to add to your code. You can control the sorting of items in the Code Completion hint window by right-clicking the box and choosing Sort by Name or Sort by Scope.
Different items appear in different colors in the Code Completon list. For example, by default, procedures are teal, functions are dark blue, and abstract methods are shown in red.
Contents |
Invoking Code Completion
Automatic code completion is on by default, and 0ptions for enabling and disabling Code Completion are located on the Tools > Options > Editor Options > Code Insight dialog box.
- When Auto Invoke is enabled for Code Completion, typing a period (.) invokes Code Completion for both Delphi and C++ (C++ also supports ->). If the Delay option is set, a delay timer runs (the cursor spins) before Code Completion is invoked.
- However, you can use
Ctrl+Spaceto invoke Code Completion in Delphi and C++ even if the Auto Invoke option is disabled.
Using Code Completion
Following are specific ways to use Code Completion in the IDE:
- To display the properties, methods, and events available in a class, press Ctrl+Space after the name of a variable that represents either a class instance or a pointer to a class instance.
- To invoke code completion for a pointer type, the pointer must first be dereferenced. For example:
- In C++, type: this->
- In Delphi, type: self.
- Type an arrow (->) for a pointer to an object.
- You can also type the name of non-pointer types followed by a period (.) to see the list of inherited and virtual properties, methods, and events. For example:
- In C++ type: TRect test;test.
- In Delphi, type: var test: TRect; begin test.
- Type an assignment operator or the beginning of an assignment statement, and press Ctrl+Space to display a list of possible values for the variable.
- In C++, type the scope operator (::).
- Type a procedure, function, or method call and press
Ctrl+Spaceto display a list of arguments that are valid for assignment to the variable entered. Select a list item followed by an ellipsis (...) to open a second list of related arguments compatible with the variable entered in the assignment statement. - Type a record (in Delphi) or a structure (in C++) to display a list of fields.
- Type an array property (not a genuine array), and press Ctrl+Space to display an index expression.
- In C++, you can also press Ctrl+Space on a blank statement line to display symbols from additional RTL units even if they are not used by the current unit.
- In Delphi, the reserved words appear in the Code Completion window if you have enabled Show reserved words on the Tools > Options > Editor Options > Code Insight dialog box. The words that appear are determined by the context when you invoke Code Completion. The current list of Delphi reserved words is available in the Delphi Language Guide (Fundamental Syntactic Elements).
Canceling Code Completion or Dismissing the Code Completion Window
When you invoke Code Completion, the cursor becomes an hour glass, indicating that the IDE is processing your request.
- To cancel a Code Completion request before the request completes, press the
Esckey. - To dismiss the Code Completion window, press the
Esckey (or simply click elsewhere).
Browsing to a Declaration
When the Code Completion window is displayed, you can hold down Ctrl and click any identifier in the list to browse to its declaration.
Also, if you hover the mouse pointer over the identifier in the Code Editor, a hint window tells where the identifier is declared. You can press Ctrl, point to the identifier in the code (it changes to blue underline, by default, and the insertion point changes to a hand pointing), and then click (with the mouse) to move to its declaration.
Note: Code Insight works only in the compilation unit. Code Completion supports WM_xxx, CM_xxx, and CN_xxx message methods based on like named constants from all units in the uses clause.
Note: For C++, Code Completion features work best when you have already built your application and have created a precompiled header. Otherwise, you need to wait for the compiler to generate the required information. It is recommended that you check the Use pre-compiled headers option on the Project > Options > Compiler dialog box.