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

Package MDDESPK.DPK

Package Structure


MDCOMPEDIT.PAS

unit MdCompEdit;

interface

uses
  DsgnIntf;

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, DsgnIntf;

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.