if-statementdelphisettingsbrackets

Is there an auto-completion feature when writing if statements?


I am developing with Delphi 10.2 Tokyo.

When I try to write a conditional expression with a () when entering an if statement, it becomes (true) when I enter ( and I have to delete the true part before writing the conditional expression.

Can I make it so that it automatically becomes () and the cursor is in the middle?

I have been trying to find out if there are any good settings in the tool options. However, I could not find any such settings.


Solution

  • What you want will work when you follow the following steps:

    1. type if in the code editor and press Space or TAB to invoke the "if"-code template
    2. type in your conditional expression
    3. press SHIFT + TAB to place the cursor at the beginning of the expression
    4. type ( (opening round bracket) and your expression should be enclosed in brackets now
    5. press TAB or ENTER to finish the input for the conditional expression

    For further references about live (or code) templates and how to add/edit them please see the official documentation:

    1. Live Templates
    2. Creating Live Templates