Using a Common Include File (Views: 10)


If you develop third-party components and you plan to include the source code. You can not be certain how Delphi is configured for each user, how can you asure that your componentīs code compile correctly?


You can use a common include file in all your components unit, so you can set compiler directives and conditional defines that govern the way the components are compiled.

If the user recompiles your code, its naive to think that his compilers directives are the same as the ones you used to develop the components. So creating a common include file, you can override the userīs directives. For example you can use the following:

// DCDC Include File
// You must include a similar file into each component unit so it can
// serve as a common place to add conditional defines and compiler
// directives.

// Code Generation Directives

{$O+} //Optimizations
{$F-} //Force Far Calls
{$A+} //Word Align Data
{$U-} //Pentium-Safe FDIV
{$K-} //Smart Callbacks
{$W-} //Windows Stack Frame

// Runtime Errors
{$R+} //Range Checking - On - If compiled with Debug Information
{$R-} //Range Checking - Off - If compiled without Debug Information

{$S+} //Stack Checking
{$I+} //I/O Checking
{$Q-} //Overflow Checking

// Syntax Options
{$V-} //Strict Var-Strings
{$B-} //Complete Boolean Evaluation
{$X+} //Extended Syntax
{$T-} //Typed @ Operator
{$P+} //Open Parameters
{4H+}//Huge Strings

// Miscellaneus Directives
{$Z-} //Word Size Enumerated Types

Because this is an include file you must use the $I directive to embed its contents in your componentīs unit files.


unit mcEdit;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

  TmcEdit = class(TCustomEdit)
    { Private declarations }
    { Public declarations }

But, what if you create a component that uses a diferent compiler directive?, Just specify the new directive after the include file statements, this overrides the include fileīs directives.

<< Back to main page