Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco


Home: Code Repository: Mastering Delphi 6

Chapter 02 - Project IfDirective

Project Structure

IfDirective.dpr
program ifdirective;

uses
  Forms,
  IfDirectiveForm in 'IfDirectiveForm.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
IfDirectiveForm.pas
unit IfDirectiveForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{$DEFINE DEBUG}

const
  DebugControl = 2;

procedure TForm1.Button1Click(Sender: TObject);
begin
{$IF Defined(DEBUG) and (DebugControl > 3)}
  ShowMessage ('Executing critical code');
{$ELSE}
  ShowMessage ('Bye');
{$IFEND}

{$IF Defined(VER140)}
  ShowMessage ('Delphi6');
{$ELSE}
  ShowMessage ('Older Delphi');
{$IFEND}

{$IFDEF WINDOWS} // Wrong!!
  ShowMessage ('Windows 16');
{$ENDIF}

{$IFDEF MSWINDOWS}
  MessageBox (0, 'Windows Platform', 'Message', MB_OK);
{$ENDIF}

{$IFDEF WIN32}
  ShowMessage ('Win32');
{$ENDIF}

{$IFDEF LINUX}
  ShowMessage ('Linux');
{$ENDIF}

  ShowMessage (FloatToStr (System.RTLVersion));
end;

var
  WindowsVersion: Integer platform = 2000;

procedure Test; platform; // notice the semicolons
begin
  Beep;
end;

type
  TWinClass = class
    x: Integer;
  end library;

{$WARN SYMBOL_PLATFORM OFF}

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage (
    IncludeTrailingBackSlash (ExtractFilePath (Application.ExeName)));
  Test;
  ShowMessage (IntToStr (WindowsVersion));
  TWinClass.Create;
  {$MESSAGE 'Old version of the unit: consider using the updated version'}
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  {$IFDEF ConditionalExpressions}
    {$IF System.RtlVersion > 14.0}
      ShowMessage ('RTL 14.0 or above');
    {$IFEND}
  {$ENDIF}
end;

end.
IfDirectiveForm.dfm
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 204
  Height = 186
  Caption = 'IfDirective'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 64
    Top = 24
    Width = 75
    Height = 25
    Caption = 'If Directive'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 64
    Top = 72
    Width = 75
    Height = 25
    Caption = 'Platfom'
    TabOrder = 1
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 64
    Top = 112
    Width = 75
    Height = 25
    Caption = 'if'
    TabOrder = 2
    OnClick = Button3Click
  end
end