1. Technology

Two Applications In One Delphi Program (Using Conditional Compilation) - Part 2

By

1 of 5

Build Configuration: Release + TRIAL
Build Configuration: Trial (extends Release)

Build Configuration: Trial (extends Release)

Zarko Gajic
The option to have different build configurations for your Delphi program allows you to have two (or more) different applications (executable files) being produced by the compiler/linker. For this purpose you would use a feature called conditional compilation.

The Conditional Compilation - Part 1 article is what you should read before you continue.

As hinted in the Part 1 of this article, conditional compilation let's you tell Delphi compiler to include or not include parts of your code depending on the existence of conditional symbols.

As explained, some conditional symbols, like "DEBUG" and "WIN32" are pre-defined in Delphi.

If you want to be able to easily have two different executable files for your program (therefore produce two different applications using the same code base), let's say "TRIAL" and "normal", you could define a conditional symbol "TRIAL_VERSION", then have lines of code like:

{$IFDEF TRIAL_VERSION}
  Caption := 'This is a TRIAL version, buy the full one to have all the features!"';
{$ENDIF}

Therefore, the question is: how to define a custom conditional symbol (like "TRIAL_VERSION")?

Build Configuration: Release + TRIAL

For the sake of simplicity, let's say you want to have a special "RELEASE" version of your program. The normal RELEASE will build your normal application, the executable will have name as specified by the project (dpr) file. The, let's call it, TRIAL RELEASE will create a differently named executable that will be the trial version of your application where some features are not allowed.

For the above, we want to have a special release version where our custom conditional symbol "TRIAL_VERSION" is defined.

We will define the TRIAL_VERSION conditional symbol as a part of a special extension to the existing RELEASE build configuration. Here's how:

  1. Expand the "Build Configurations" node under "Project1" in "ProjectGroup1" inside the Project Manger,
  2. Right click the "Release" build configuration and select "New Configuration..." from the popup menu.
  3. Let the name for the new configuration build be "TRIAL" on the New Build Configuration dialog.
  4. The TRIAL is now a sub-node to the Release build configuration node.
The TRIAL build configuration extends the Release configuration, and for the moment they are the same.

Let's now see how to add our custom conditional symbol "TRIAL_VERSION" to the "TRIAL" build configuration.

  1. About.com
  2. Technology
  3. Delphi
  4. Coding Delphi Applications
  5. Two Applications In One Delphi Program (Using Conditional Compilation) - Part 2 / 1

©2014 About.com. All rights reserved.