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 6

Chapter 11 - Package MdDesPk

Package Structure

MdArrReg.pas
unit MdArrReg;

interface

uses
  DesignIntf, Classes;

procedure Register;

implementation

uses
  MdArrow;

procedure Register;
begin
  RegisterComponents ('Md', [TMdArrow]);
  RegisterPropertyInCategory (
    'Input', TMdArrow, 'OnArrowDblClick');
  RegisterPropertyInCategory (
    'Arrow', TMdArrow, 'Direction');
  RegisterPropertyInCategory (
    'Arrow', TMdArrow, 'ArrowHeight');
  RegisterPropertyInCategory (
    'Arrow', TMdArrow, 'Filled');
  RegisterPropertyInCategory (
    'Visual', TMdArrow, 'Filled');
end;

end.
MdCompEdit.pas
unit MdCompEdit;

interface

uses
  DesignIntf, DesignEditors;

type
  TMdListCompEditor = class (TComponentEditor)
    function GetVerbCount: Integer; override;
    function GetVerb(Index: Integer): string; override;
    procedure ExecuteVerb(Index: Integer); override;
    procedure Edit; override;
  end;

procedure Register;

implementation

uses
  SysUtils, Dialogs, StdCtrls, MdListDial;

function TMdListCompEditor.GetVerbCount: Integer;
begin
  Result := 3;
end;

function TMdListCompEditor.GetVerb (Index: Integer): string;
begin
  case Index of
    0: Result := 'MdListDialog (©Cantý)';
    1: Result := '&About this component...';
    2: Result := '&Preview...';
  end;
end;

procedure TMdListCompEditor.ExecuteVerb (Index: Integer);
begin
  case Index of
    0..1: MessageDlg (
      'This is a simple component editor'#13 +
      'built by Marco Cantý'#13 +
      'for the book "Mastering Delphi"',
      mtInformation, [mbOK], 0);
    2: with Component as TMdListDialog do
      Execute;
  end;
end;

procedure TMdListCompEditor.Edit;
begin
  // produce a beep and show the about box
  Beep;
  ExecuteVerb (0);
end;

procedure Register;
begin
  RegisterComponentEditor (
    TMdListDialog, TMdListCompEditor);
end;

end.
PeFSound.pas
unit PeFSound;

interface

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

type
  TSoundForm = class(TForm)
    Label1: TLabel;
    btnOK: TBitBtn;
    btnCancel: TBitBtn;
    btnLoad: TSpeedButton;
    OpenDialog1: TOpenDialog;
    btnPlay: TBitBtn;
    ComboBox1: TComboBox;
    procedure btnLoadClick(Sender: TObject);
    procedure btnPlayClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SoundForm: TSoundForm;

implementation

{$R *.DFM}

uses
  MMSystem;

procedure TSoundForm.btnLoadClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
    ComboBox1.Text := OpenDialog1.FileName;
end;

procedure TSoundForm.btnPlayClick(Sender: TObject);
begin
  PlaySound (PChar (ComboBox1.Text), 0, snd_Async);
end;

end.
PeSound.pas
unit PeSound;

interface

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

type
  TSoundProperty = class (TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure Edit; override;
  end;

procedure Register;

implementation

uses
  MdSounB, // component unit
  PeFSound; // sound editor form

function TSoundProperty.GetAttributes:
  TPropertyAttributes;
begin
  // allow direct editing and multiple selection
  Result := [paDialog, paMultiSelect, paValueList, paSortList];
end;

procedure TSoundProperty.GetValues(Proc: TGetStrProc);
begin
  // provide a list of system sounds
  Proc ('Maximize');
  Proc ('Minimize');
  Proc ('MenuCommand');
  Proc ('MenuPopup');
  Proc ('RestoreDown');
  Proc ('RestoreUp');
  Proc ('SystemAsterisk');
  Proc ('SystemDefault');
  Proc ('SystemExclamation');
  Proc ('SystemExit');
  Proc ('SystemHand');
  Proc ('SystemQuestion');
  Proc ('SystemStart');
  Proc ('AppGPFault');
end;

procedure TSoundProperty.Edit;
begin
  SoundForm := TSoundForm.Create (Application);
  try
    SoundForm.ComboBox1.Text := GetValue;
    // show the dialog box
    if SoundForm.ShowModal = mrOK then
      SetValue (SoundForm.ComboBox1.Text);
  finally
    SoundForm.Free;
  end;
end;

procedure Register;
begin
  RegisterPropertyEditor (TypeInfo(string),
    TMdSoundButton, 'SoundUp', TSoundProperty);
  RegisterPropertyEditor (TypeInfo(string),
    TMdSoundButton, 'SoundDown', TSoundProperty);
end;

end.