Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my {$IFDEF DEBUG} conditional not working in Delphi?

I have the following code (IP addresses changed) in a Delphi 7 project.

const
{$IFNDEF DEBUG}
    AUTHENTICATOR_DB_ADMIN_HOST = '123.456.789.12';
{$ELSE}
    AUTHENTICATOR_DB_ADMIN_HOST = '127.0.0.1';
{$ENDIF}

Under project options:

  • In the "Directories/Conditionals" tab under the section marked "Conditionals", I have a single definition: "DEBUG".
  • In the "Version Info" tab under the section marked "Module Attributes", I have ticked the checkbox labelled "Debug-build".

In the above code example, the "DEBUG" symbol is not defined, so the IP address is set to 123.456.789.12 instead of 127.0.0.1. What am I doing wrong?

This question is following on from Does Delphi's conditional compilation allow the defined symbols to contain values?

like image 587
magnus Avatar asked Mar 12 '14 02:03

magnus


1 Answers

If you compile your project and there are no changes and the DCU is available on the path for the last non debug build then it will be used, causing this problem. Also make sure this unit is included in the uses clause of the DPR.

If you build the project it will force a recompile of all units added to the project.

I generally compile for syntax but always build for testing/deployment.

like image 131
skamradt Avatar answered Nov 15 '22 07:11

skamradt