| Code Completion in Delphi | |||||||||||||||||||||||
| It's time to learn how to let Delphi help you code faster: start using code templates, code insight, code completion, shortcut keys, ... | |||||||||||||||||||||||
Welcome to the thirteenth chapter of the FREE online programming course: How to code faster and more efficiently
And how about writing the MessageDlg function? Do you know all the parameters (and their order) this method expects? I do not know, neither do I tend to remember each functions parameter list. I simply write "MessageDlg" and hit Ctrl + Space + Shift: the list of all the parameters gets shown in a tool tip.
The answer is: Delphi Code Insight! ![]() Note: you can always invoke Code completion using Ctrl + Space. Another example includes the following situation: When the code completion list is displayed, you can hold down the Ctrl key and click on any identifier in the list to browse to its declaration (if you have the sources of Borland Delphi units, you can see "inside" Delphi). Also, in the Code editor, if you hover the mouse pointer over the identifier, a hint window tells where it is declared. You can press Ctrl, point to the identifier in the code and click to move to its declaration. "Unable to invoke Code Completion due to errors in source code"? Code TemplatesAs suggested above, this feature can save you lots of keystrokes. Templates include commonly used programming statements (such as if, while, for and tyr/finally/end statements) - each statement has a shortcut, eg. "forb" is a for loop with begin end. You simply start a statement by typing several characters and press Ctrl+J and pick from a list of predefined code templates.![]() Another great example includes pressing Ctrl+J on a blank line, typing f, and double-clicking the selected function declaration - the function skeleton code will be inserted automatically at the current cursor position. Code ParametersThis tool enables you to see the arguments of a method call as you enter them into your code. After typing a method and a '(', a description of the parameters will be displayed, as each parameter is input the next parameter to be input is highlighted in bold. Use Ctrl+Shift+Space to activate or reactivate if the tooltip disappears.![]() Tooltip symbol insight, Tooltip expression evaluation Class CompletionThis is a "subset" of the code completion feature, designed to automate the definition of (new) classes by generating skeleton code for the class members. This is how it works:You write a new property declaration inside a public section of the interface section of your class definition (Form1).
When complete hit Ctrl + Shift + C, Delphi automatically adds private read and write specifiers to the declarations, then adds skeleton code in the implementation section. This is what gets added by Delphi:
Code Insight SettingsOptions for turning Code Insight tools on and off are located on the Code Insight page of the Tools | Editor Options dialog.![]() Note that all the Code Insight tools have lot more usage ways. The list can be found on Delphi Help under "Code Insight" when you click Help in the above dialog. Some exercises for you...Hmm, simply start using Code insight features, you will not believe how much time you can save in coding, and of course you can drastically reduce the number of bugs in your code. To the next chapter: A Beginner's Guide to Delphi Programming If you need any kind of help at this point, please post to the Delphi Programming Forum where all the questions are answered and beginners are treated as experts. A Beginner's Guide to Delphi Programming: Next Chapter >> |
|||||||||||||||||||||||





