Logo Delphi Handbooks Collection

Delphi Developer Days 2012
March-May
Cantù-Jensen
(UK, NL, US, D, I)

Menu for Development

Site Menu
Delphi 2010 Handbook
Delphi 2009 Handbook
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)

Advertising
Home My Blog Handbooks Development Links Marco
Delphi Developer Days 2012



Home: Code Repository: Mastering Delphi 5

Project ASSERT

Project Structure


ASSERT.DPR

program Assert;

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

{$R *.RES}

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

ASSERTF.PAS

unit AssertF;

interface

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

type
  TForm1 = class(TForm)
    BtnInc: TButton;
    BtnDec: TButton;
    ProgressBar1: TProgressBar;
    procedure BtnIncClick(Sender: TObject);
    procedure BtnDecClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    Number: Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

// disable assertions
// {$C-}

procedure TForm1.BtnIncClick(Sender: TObject);
begin
  if Number < 100 then
    Inc (Number);
  ProgressBar1.Position := Number;
  // test the condition
  Assert ((Number > 0) and (Number <= 100));
end;

procedure TForm1.BtnDecClick(Sender: TObject);
begin
  if Number > 0 then
    Dec (Number);
  ProgressBar1.Position := Number;
  // test the condition
  Assert ((Number > 0) and (Number <= 100));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Number := 1;
end;

end.

ASSERTF.DFM

object Form1: TForm1
  Left = 305
  Top = 160
  Width = 248
  Height = 161
  Caption = 'Assertions Test'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object BtnInc: TButton
    Left = 32
    Top = 16
    Width = 75
    Height = 25
    Caption = '&Inc'
    TabOrder = 0
    OnClick = BtnIncClick
  end
  object BtnDec: TButton
    Left = 144
    Top = 16
    Width = 75
    Height = 25
    Caption = '&Dec'
    TabOrder = 1
    OnClick = BtnDecClick
  end
  object ProgressBar1: TProgressBar
    Left = 32
    Top = 64
    Width = 185
    Height = 33
    Min = 1
    Max = 100
    Position = 1
    TabOrder = 2
  end
end