Unexpected Benefit of Inline Variables: Conditional Blocks

Posted by on in Blogs

Inline variables is one of the cool new feature coming in 10.3. The obvious huge use case is loop control variables, but I just discovered another great use case while reviewing some code. 

procedure DoesSomething; var var1, var2: Integer; begin // use var1 {$IFDEF Something} // use var1 & var2 {$ENDIF Something} end;

This is a pattern I see a lot, and it generates a hint on var2 being unused based on the current compiler directive status.

[dcc32 Hint] myUnit.pas(123): H2164 Variable 'var2' is declared but never used in 'DoesSomething'

Now there are a number of ways to deal with this with more compiler directives, which is what I’ve done in the past, but I never like adding more compiler directives. It makes the code way more complicated and harder to maintain. Now with Inline Variables I can simplify it, make it easier to maintain, and hande the hint! (all of which makes me so happy!)

procedure DoesSomething; var var1: Integer; begin // use var1 {$IFDEF Something} var var2: Integer; // use var1 and var2 {$ENDIF Something} end; Happy dance commencing in T-minus 10 seconds. 

What are some interesting ways you see inline variables benefiting you?



Comments

  • nacymack
    nacymack Monday, 26 November 2018

    Interesting post I really enjoyed for this post and never before for this type of post it is useful for me and gets Do My Assignment and some of the new ideas keep more posting thanks.

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: