Marco Cantù 1998, Mastering Delphi 4
Project: PROCTYPE.DPR
Project Structure
PROCTYPE.DPR
program Proctype;
uses
Forms,
ProcForm in 'ProcForm.pas' {Form1};
{$R *.RES}
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
PROCFORM.PAS
unit ProcForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
type
{procedure type definition}
IntProc = procedure (var Num: Integer);
TForm1 = class(TForm)
ApplyButton: TButton;
DoubleRadioButton: TRadioButton;
TripleRadioButton: TRadioButton;
procedure FormCreate(Sender: TObject);
procedure ApplyButtonClick(Sender: TObject);
procedure DoubleRadioButtonClick(Sender: TObject);
procedure TripleRadioButtonClick(Sender: TObject);
private
{ Private declarations }
IP: IntProc;
X: Integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{procedures of the IntProc type}
procedure DoubleTheValue (var Value: Integer);
begin
Value := Value * 2;
ShowMessage ('Value doubled: ' + IntToStr (Value));
end;
procedure TripleTheValue (var Value: Integer);
begin
Value := Value * 3;
ShowMessage ('Value tripled: ' + IntToStr (Value));
end;
{initialization code}
procedure TForm1.FormCreate(Sender: TObject);
begin
IP := DoubleTheValue;
X := 2;
end;
{push button OnClick event}
procedure TForm1.ApplyButtonClick(Sender: TObject);
begin
IP (X);
end;
{Radio buttons OnClick events}
procedure TForm1.DoubleRadioButtonClick(Sender: TObject);
begin
IP := DoubleTheValue;
end;
procedure TForm1.TripleRadioButtonClick(Sender: TObject);
begin
IP := TripleTheValue;
end;
end.
PROCFORM.DFM
object Form1: TForm1
Left = 201
Top = 141
Width = 305
Height = 179
ActiveControl = ApplyButton
Caption = 'Proc Type'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ApplyButton: TButton
Left = 168
Top = 56
Width = 89
Height = 41
Caption = 'Apply'
TabOrder = 0
OnClick = ApplyButtonClick
end
object DoubleRadioButton: TRadioButton
Left = 40
Top = 40
Width = 81
Height = 33
Caption = 'Double'
Checked = True
TabOrder = 1
TabStop = True
OnClick = DoubleRadioButtonClick
end
object TripleRadioButton: TRadioButton
Left = 40
Top = 88
Width = 81
Height = 25
Caption = 'Triple'
TabOrder = 2
OnClick = TripleRadioButtonClick
end
end
Copyright Marco Cantù 1998