Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 5

Project IFSENDER

Project Structure


IFSENDER.DPR

program IfSender;

uses
  Forms,
  SendForm in 'SendForm.pas' {SenderForm};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TSenderForm, SenderForm);
  Application.Run;
end.

SENDFORM.PAS

unit SendForm;

interface

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

type
  TSenderForm = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    BitBtn1: TBitBtn;
    Button2: TButton;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    procedure ShowSender(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SenderForm: TSenderForm;

implementation

{$R *.DFM}

procedure TSenderForm.ShowSender(Sender: TObject);
begin
  Memo1.Lines.Add ('Class Name: ' +
    Sender.ClassName);

  if Sender.ClassParent <> nil then
    Memo1.Lines.Add ('Parent Class: ' +
      Sender.ClassParent.ClassName);

  Memo1.Lines.Add ('Instance Size: ' +
    IntToStr (Sender.InstanceSize));

  // if the object is (exactly) of the TButton type
  if Sender.ClassType = TButton then
    Memo1.Lines.Add ('TButton ClassType');

  // if the object is a given object
  if Sender = Button1 then
    Memo1.Lines.Add ('This is Button1');

  if Sender.InheritsFrom (TButton) then
    Memo1.Lines.Add ('Sender inherits from TButton');

  if Sender is TButton then
    Memo1.Lines.Add ('Sender is a TButton');

  // leave a blank line
  Memo1.Lines.Add ('');
end;

end.

SENDFORM.DFM

object SenderForm: TSenderForm
  Left = 229
  Top = 192
  Width = 383
  Height = 361
  Caption = 'SenderForm'
  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 = 16
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = ShowSender
  end
  object Memo1: TMemo
    Left = 104
    Top = 16
    Width = 257
    Height = 305
    TabOrder = 1
  end
  object BitBtn1: TBitBtn
    Left = 16
    Top = 80
    Width = 75
    Height = 25
    Caption = 'BitBtn1'
    TabOrder = 2
    OnClick = ShowSender
  end
  object Button2: TButton
    Left = 16
    Top = 48
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 3
    OnClick = ShowSender
  end
  object CheckBox1: TCheckBox
    Left = 16
    Top = 112
    Width = 73
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 4
    OnClick = ShowSender
  end
  object Edit1: TEdit
    Left = 16
    Top = 136
    Width = 73
    Height = 21
    TabOrder = 5
    Text = 'Edit1'
    OnClick = ShowSender
  end
end