How do I change the way the RAD Studio (2010 and later) IDE formats my code?

前端 未结 1 1514
花落未央
花落未央 2021-02-18 17:41

How do I configure the RAD Studio IDE to format my code with begin on either the same or next line when I use the Format Source option?

One of

相关标签:
1条回答
  • 2021-02-18 17:50

    I am answering this question Q&A style.

    1. Go to Tools > Options
    2. Find the Formatter section in the tree on the left
    3. Inside that node, select Delphi > Line Breaks
    4. Locate the section on the right labeled Insert line breaks for Begin and Single instructions
    5. Inside here, find the setting labeled Line breaks before Begin in control statements
    6. Switch this setting between Yes or No depending on your preference.

    Switch between Yes and No to change how begin is positioned

    Yes will produce this:

    if (Foo = Bar) then
    begin
    
    end;
    

    No will produce this:

    if (Foo = Bar) then begin
    
    end;
    

    By default, this setting is set to Yes which means when you use Format Source, it will always bring begin to the next line.

    There are many settings in this section which can define how Format Source will treat your code. This option is available in at least RAD Studio 2010 and above. Not sure of which exact editions.

    Note: Ctrl + D is a keyboard shortcut to format your source, a quicker alternative.

    0 讨论(0)
提交回复
热议问题