Search code examples
delphidelphi-10.2-tokyo

How to increment sequential Const values when adding a new one in the middle


I have a code like this

const
value1 = 1;
value2 = 2;
value4 = 3;
.
.
.
valuen = n;

and say I want to add value3 = 3; to the list without having to deal with the pain of editing all the values to n.

Is there a intrinsic method or a trick that can be done to make this easier in the future?


Solution

  • Use the Delphi editor.

    • Step 1: Add the new const variable in its right place:

      const
        value1 = 1;
        value2 = 2;
        value3 =
        value4 = 3;
        value5 = 4;
        value6 = 5;
        value7 = 6;
      
    • Step 2: Use the column block selection shortcut to select from 3 to the end of the list. To turn on column mode selection, press Ctrl+O+C and mark the block. Alternatively, drag the mouse with the Alt key down.

    enter image description here

    • Step 3: Cut and paste the section to one line up.

    enter image description here

    • Step 4: Finally, enter the last value. Job done in a couple of seconds.

    enter image description here