A compiler curiosity I've learned today:

A compiler curiosity I've learned today:

// This works:
{$IF Declared(Test) and (Test>=100)}
{$ENDIF}

// This not:
{$IF Declared(Test)}
{$IF Test>=100} // "E2026 Constant expression expected"
{$ENDIF}
{$ENDIF}

Comments

  1. What doesn't work? i.e. do you get an error, is some code included that shouldn't? something else?

    ReplyDelete
  2. Yes, error "E2026 Constant expression expected" at "$IF Test..."

    ReplyDelete
  3. Looks like the compiler is evaluating the $IF despite being in a block that should not.

    Funny enough I get a W1023 when Test is not declared in the first version facepalm

    ReplyDelete
  4. Stefan Glienke yes, forgot about that. The 1023 warning disappears adding a + in front of 100

    ReplyDelete
  5. Did you try $IF (Test>=100) ? I don't have an IDE at hand right now

    ReplyDelete
  6. Joaquin Menemene yes, parenthesis or spacing aren't important

    ReplyDelete

Post a Comment