Recent

Author Topic: define application release mode or debug mode  (Read 588 times)

Prakash

  • Full Member
  • ***
  • Posts: 240
define application release mode or debug mode
« on: July 25, 2024, 08:09:58 am »
{$DEFINE DEBUG}
        with TFileStream.Create('d:\data.json', fmCreate) do
        begin
          try
            S := datajson.AsJSON;
            WriteBuffer(S[1], Length(S));
          finally
            Free;
          end;
        end;
        {$IFDEF RELEASE}
        {$ENDIF}   

I want to execute this code only my application is in debug mode .

how and where to define application debug or release mode

TRon

  • Hero Member
  • *****
  • Posts: 3128
All software is open source (as long as you can read assembler)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: define application release mode or debug mode
« Reply #2 on: July 25, 2024, 08:41:45 am »
Or to be a bit more specific:

1. Create Debug/Release mode as shown in the first link.
2. Create a custom options entry as shown a bit below that (see attached screenshot) - it will affect only the currently selected one.

your code won't compile though, {$IFDEF} needs a matching {$ENDIF}. I.e. something like:

Code: Pascal  [Select][+][-]
  1. {$IFDEF DEBUG}
  2. with TFileStream.Create('d:\data.json', fmCreate) do
  3. begin
  4.   try
  5.     S := datajson.AsJSON;
  6.     WriteBuffer(S[1], Length(S));
  7.   finally
  8.     Free;
  9.   end;
  10. end;
  11. {$ELSE}
  12.   //Do something in not-debug mode
  13. {$ENDIF}
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: define application release mode or debug mode
« Reply #3 on: July 25, 2024, 10:48:09 am »
The correct option is
Code: Pascal  [Select][+][-]
  1. {$ifopt d+}
This can be used with any global compiler directive, btw.
{$ifopt <x>+/-} can be used multiple times.
« Last Edit: July 25, 2024, 11:01:59 am by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

Warfley

  • Hero Member
  • *****
  • Posts: 1522
Re: define application release mode or debug mode
« Reply #4 on: July 25, 2024, 11:01:06 am »
The correct option is
Code: Pascal  [Select][+][-]
  1. {$ifopt d+}
This can be used with any global compiler directive, btw.

This is not a debug mode, this is for when debug symbols are present, which you may also want to have in the release build of your program, e.g. to do logging, or for performance measurements. If your goal is to have code that is only in a debug build, you should create a debug build with a define.

Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: define application release mode or debug mode
« Reply #5 on: July 25, 2024, 11:04:10 am »
Wrong.
It is equivalent to specify -dDEBUG on the command line.
The advantage is that it can be used for any global compiler directive.
I thought you knew that? Rather basic since tp days.
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

 

TinyPortal © 2005-2018