Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 6

Chapter 02 - Project FormProp

Project Structure

FormProp.dpr
program FormProp;

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

{$R *.RES}

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

interface

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

type
  TForm1 = class(TForm)
    btnCreateForm: TButton;
    procedure FormClick(Sender: TObject);
    procedure btnCreateFormClick(Sender: TObject);
  private
    FClicks: Integer;
    procedure SetClicks(const Value: Integer);
    { Private declarations }
  public
    property Clicks: Integer read FClicks write SetClicks;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.SetClicks(const Value: Integer);
begin
  FClicks := Value;
end;

procedure TForm1.FormClick(Sender: TObject);
begin
  Inc (FClicks);
  Caption := 'Clicks: ' + IntToStr (FClicks);
end;

procedure TForm1.btnCreateFormClick(Sender: TObject);
begin
  with TForm1.Create (Self) do
    Show;
end;

end.
FormFProp.dfm
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 474
  Height = 215
  Caption = 'FormProp'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDefaultPosOnly
  OnClick = FormClick
  PixelsPerInch = 96
  TextHeight = 13
  object btnCreateForm: TButton
    Left = 16
    Top = 16
    Width = 89
    Height = 25
    Caption = 'Create Form'
    TabOrder = 0
    OnClick = btnCreateFormClick
  end
end