Features of Delphi code editor

Source: Internet
Author: User
Tags list of attributes

Delphi code editor has several features that are useful when writing large-scale code. The following sections describe:

1. Code templates (Code Template)

You can use a code template to insert any predefined code (or body) into a unit file. When editing code in code editor, press Ctrl + J on the keyboard to use the code template. A list box is displayed, listing available templates. Select a template from the list and press Enter. The body corresponding to the template is inserted into the unit file. For example:

You can add a new template or edit an existing template on the "Code insight" page of the "Environment options" dialog box. Alternatively, you can use a text editor to open the code template file and edit the code template. The code template file is delphi32.dci, which is located in the bin directory under the Delphi installation directory.

You can freely modify the code template. For example, you can modify the code template that represents the for statement as follows:

for I := 0 to Pred(|) dobeginend;

Note the Pipeline character (|) above ). The pipeline in the code template is a location identifier, which determines the position of the cursor in the body insert code.

Tip

If you have made major changes to the Code Template file, you must back up the modified Code Template file for future use. When you update or reinstall Delphi, the Delphi installer overwrites the modified delphi32.dci file.

The code template is not only used for code. For example, the following code:

{****************************************************}{*               Filename and Version               *}{*         Copyright(C) pchmonster 2012        *}{*               All rights reserved.               *}{****************************************************}

The copyright information in this comment remains unchanged. Therefore, you can create a template to quickly add the copyright information to the newly created unit. You can make the text frequently used in routine programming into a code template.

2. Code Parameters)

The Code parameter feature of Code Editor provides a tooltip to notify users of the parameter information required by the VCL method or API function. There are hundreds of VCL methods and Windows API functions. It is very difficult to remember the parameters of each function. When you type a method name, the Code parameter feature shows the parameters of the method to save your events. For example, if you call the setbounds method, a prompt window is displayed after you type the left parenthesis, for example:

Each parameter is listed in the prompt window. The parameters to be entered are displayed in bold. After you type a parameter, the parameters are displayed in bold until all parameters are entered. After all parameters are entered, the Code parameter Prompt window disappears. You can set the code Parameter options on the "Code insight" page of the "Environment options" dialog box.

3. Code Completion (Code completed)

When you add a class variable name and a dot operator (.), Code Editor displays a list box listing all the attributes and methods of the class. For example, if you have a memo component, type:

Memo.

After a pause, the following list box will pop up:

Next, you can select items in the table in two ways.

  • Method 1: use the mouse or keyboard to specify an attribute or method in the list box, and press enter to insert the specified attribute and method into the code.
  • Method 2: Enter the first few letters of the attribute or method in the code to be inserted. Delphi searches for the matching attribute or method in the list box and highlights the items that match the most input letters, if this item is the desired property or method, press enter to insert it into the code.

If you do not want to use the Code Completion list box, press the ESC key on the keyboard and the list box will disappear.

Code Completion provides a list of attributes and methods for users to choose from, saving user events and avoiding spelling and case errors of attribute names and method names. You can select the desired property or method, press enter, and Delphi will insert it into the code.

4. tooltip symbol insight (tooltip)

Move the cursor over any identifier in the source code, and a prompt box will pop up. For example, in any standard project interface segment, move the cursor to "tform1 = Class (tform, the following window is displayed:

This line shows the tform class declaration and tells the user that tform is declared in line 704 of the forms. Pas unit.

This tooltip will tell you information about any variable in the program. It is especially convenient to use this function when you forget the type of a variable.

5. Class completion (completed by class)

After you type a declaration of a method or attribute in the interface segment and press Ctrl + Shift + C, Delphi will add the required code to the Implementation implementation segment, to complete this class. The following is a simple link to familiarize yourself with this feature:

(1) Start an empty project.

(2) switch to code editor and find the Form class declaration in the interface section.

(3) type the following code in the public section of the Form class declaration:

(4) press Ctrl + Shift + C. Delphi automatically adds the code of the test and getsomething methods to the implementation section and positions the cursor in the first method. For example:

Class completion applies to attribute declarations and methods. Type an attribute declaration and press Ctrl + Shift + C. Delphi will automatically complete the declaration of this attribute. It can also add a write method for the attribute. It is a little difficult to understand this write method. After you can write your own components in the future, you will understand it.

The class completion feature saves a lot of time when writing components. After using it for a while, you will feel that you can no longer leave it.

6. Module navigation)

It enables you to quickly move a method from the implementation section to the method declaration in the interface Section. This can also be done in turn. Let's make an exercise to illustrate it.

(1) Find the Exercise above. we modified the Form class declaration and added the getsomething and test methods;

(2) Click the row that contains the declaration of the test process;

(3) press Ctrl + Shift + downward arrow to jump to the test process code section of implementation;

(4) press Ctrl + Shift + up arrow. The Code Editor jumps to the declaration of the test process in the interface segment;

The module navigation makes it easy to move between implementation and interface segments quickly.

Tip

It does not matter if you use an arrow or a down arrow. You can use either of the buttons to switch back and forth between the interface and implementation segments.

7. Module browsing)

Module browsing is another module navigation tool. In code editor, press Ctrl and place the cursor over an identifier name. The identifier is highlighted in blue and underlined. Click this identifier, delphi will tell you where the identifier is declared in the source code.

The module browsing class is similar to the module navigation feature. However, module browsing also has other functions. You can click either the VCL identifier or your own identifier for module browsing. The following is an example.

1) create a new application and place a button component and a memo component on its form.

2) select project | options from the main menu ]. Click the "directories/conditionals" tab in the "Project Options" dialog box. Enter the following content in the search path field:

$(DELPHI)\Source\Vcl;$(DELPHI)\Source\Rtl\Win

Click OK to close the "Project Options" dialog box.

3) double-click the button1 button on the form to add the onclick event handler to it as follows:

Tmemo's clear method clears memo content. Do you really want to know what the VCL source code of the clear method is? Continue.

4) press Ctrl on the keyboard and Click Clear. For example:

5) after a moment, the code editor displays the VCL stdctrls unit, and the cursor stops at the tcustomedit. Clear method (this clear method is defined in the tcustomedit class, which is one of the tmemo ancestor classes ). The clear method looks like this:

Is it interesting? There is only one line of code. But where does setwindowtext come from? Continue to the next step.

6) press Ctrl and click setwindowtext.

A few seconds later, the Windows unit is opened and the cursor is on the following line, for example:

The line with the red line above tells us that setwindowtext is a Windows function, which is included in the USER32 dynamic link library.

7) See the back and next buttons in the upper-right corner of the code editor window. Click Back and switch code editor to the previous browser (the clear method in stdctrls ).

8) Click the next button and the code editor displays the setwindowtext entry in the Windows unit Portal.

9) Click the drop-down arrow next to the back button and the source code unit will appear in the browser records table. Click a unit to switch the code editor to this unit.

The module browser is a powerful tool that not only allows you to navigate your own code, but also the VCL source code and the source code of the third-party component library installed by you. Remember: you can learn a lot by reading the VCL source code. Do not be afraid to browse the source code.

8. Using bookmarks (using bookmarks)

You can set bookmarks in the code to temporarily mark the position in the source code. For example, you often need to temporarily leave a piece of code that you are working on to view the previously written code or copy the code from another location; set a bookmark at the current code location, and then leave to do other things, you can return to the code snippet with only one click. You can set up to 10 bookmarks at a time.

To exit a certain position and set bookmarks, press Ctrl + Shift + bookmarks ]. For example, you need to set bookmarks 0 (the first one), move the editor cursor to the position to be marked, and press Ctrl + Shift + 0 or Ctrl + K + 0 ]. After the bookmarks are set, an icon is displayed in the code editor groove to indicate the row where the bookmarks are located. This icon displays the bookmarks. For example:

To return to the bookmarks, press Ctrl + bookmarks. For example, CTRL + 1 is returned to bookmarks 1. You can also set bookmarks and return bookmarks in the right-click menu of code editor. To clear a bookmarks, you can move the editor cursor to the row where the bookmarks are located, and press Ctrl + Shift + bookmarks again to clear the bookmarks.

Note

You can set bookmarks for each file opened in code editor. For example, you can set 1 # bookmarks in one source code and 1 # bookmarks in another source file. This means that bookmarks cannot be searched across source files. If you set 1 # bookmarks in unit1.pas, pressing CTRL + 1 in unit2.pas cannot return the position where 1 # bookmarks are located in unit1.pas.

Bookmarks are temporary. When the source file is closed and re-opened, the previously set bookmarks do not exist. Note that the key on the primary key must be used to set and delete bookmarks. The key on the keypad does not work.

9. incremental search (incremental search)

You can use the incremental search option to quickly find short character sequences. Choose search | incremental search from the main menu or press Ctrl + e to start incremental search. To understand how incremental search works, the best way is to do an exercise. follow these steps:

1) Use "Object repository" to create a new text file;

2) enter the following body:

Learning to write WindowsPrograms a bit at a timeis not so bad. Isn't ittime you go back to work?

3) move the cursor to the file header [Ctrl + Home ];

4) press Ctrl + e to start the incremental search and find "back ". Note that "Searching for:" is displayed in the code editor status bar :";

5) Input B on the keyboard. The letter B in the word bit is highlighted, but this is not to be searched.

6) input a value from the keyboard. This Highlight shows the BA in bad, which is still not to be searched.

7) input a C from the keyboard. Highlight the BAC in the back field,

Enter K, and the status bar of code editor displays "Searching for: Back", and the back is highlighted. In this way, the content to be searched is found.

8) Press ESC on the disk to stop incremental search.

This is all about it. When the body to be searched is short, It is very convenient to use incremental search.

Tip

If an incorrect character is entered during incremental search, you can use the backspace key to delete the character that is incorrectly entered in the search string.

10. Finding matching brackets and parentheses (search for matching brackets and parentheses)

Code Editor also has a feature that helps you find square brackets or parentheses that you want to pair with the square brackets or parentheses referred to by the current cursor. To search for matching square brackets, move the cursor to the square brackets. Press [Alt + [] on the keyboard, and the cursor will jump to the square brackets to be paired with this square brackets.

Then press [Alt + [] to jump back to the start position. Use the same strike key for the parentheses and square brackets. Sometimes it may be lost in the maze of parentheses and square brackets, but now we should be able to find the way out of the maze.

The above code has passed the test in Delphi7.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.