Property Editor

Top  Previous  Next

 

 

Type

TComponentEditor = class

private

  FComponent: TComponent;

  FDesigner: TFormDesigner;

public

  constructor Create(AComponent: TComponent;

                     ADesigner: TFormDesigner); virtual;

  procedure Edit; virtual;

  procedure ExecuteVerb(Index: Integer); virtual;

  function GetVerb(Index: Integer): string; virtual;

  function GetVerbCount: Integer; virtual;

  procedure Copy; virtual;

 

  property Component: TComponent read FComponent;

  property Designer: TFormDesigner read FDesigner;

end;

 

 

procedure TCommonDialogComponentEditor.Edit;

begin

  if (Component IS TOpenDialog) then { also TSaveDialog }

    (Component AS TOpenDialog).Execute

  else

    if (Component IS TPrintDialog) then

      (Component AS TPrintDialog).Execute

    else

      if (Component IS TPrinterSetupDialog) then

        (Component AS TPrinterSetupDialog).Execute

      else

        if (Component IS TColorDialog) then

          (Component AS TColorDialog).Execute

        else

          inherited Edit { default behaviour }

end {Edit};

 

 

unit CompEdit;

{ TCommonDialogComponentEditor version 0.1 }

interface

uses

DsgnIntf;

 

Type

TCommonDialogComponentEditor = class(TComponentEditor)

public

  procedure Edit; override;

end;

 

procedure Register;

 

implementation

uses

Dialogs;

 

procedure TCommonDialogComponentEditor.Edit;

begin

  if (Component IS TOpenDialog) then { also TSaveDialog }

    (Component AS TOpenDialog).Execute

  else

    if (Component IS TPrintDialog) then

      (Component AS TPrintDialog).Execute

    else

      if (Component IS TPrinterSetupDialog) then

        (Component AS TPrinterSetupDialog).Execute

      else

        if (Component IS TColorDialog) then

          (Component AS TColorDialog).Execute

        else

          inherited Edit { default behaviour }

end {Edit};

 

procedure Register;

begin

  { register TCommonDialogComponentEditor for

    TCommonDialog and all its derived classes }

  RegisterComponentEditor(TCommonDialog, TDialogEditor)

end;

end.

 

unit FileName;

interface

uses

SysUtils, DsgnIntf;

 

Type

TFileNameProperty = class(TStringProperty)

public

  function GetAttributes: TPropertyAttributes; override;

  procedure Edit; override;

end;

 

procedure Register;

 

implementation

uses

Dialogs, Forms;

 

function TFileNameProperty.GetAttributes: TPropertyAttributes;

begin

  Result := [paDialog]

end {GetAttributes};

 

procedure TFileNameProperty.Edit;

begin

  with TOpenDialog.Create(Application) do

  try

    Title := GetName; { name of property as OpenDialog caption }

    Filename := GetValue;

    Filter := 'All Files (*.*)|*.*';

    HelpContext := 0;

    Options := Options + [ofShowHelp, ofPathMustExist, ofFileMustExist];

    if Execute then SetValue(Filename);

  finally

    Free

  end

end {Edit};

 

procedure Register;

begin

  RegisterPropertyEditor(TypeInfo(TFileName),nil, '', TFileNameProperty)

end;

end.

 

 

unit PictEdit;

interface

uses

DsgnIntf;

 

Type

TPictureEditor = class(TClassProperty)

public

  function GetAttributes: TPropertyAttributes; override;

  procedure Edit; override;

end;

 

procedure Register;

 

implementation

uses

SysUtils, Controls, Graphics, TypInfo, ImageFrm;

 

function TPictureEditor.GetAttributes: TPropertyAttributes;

begin

  Result := [paDialog]

end {GetAttributes};

 

procedure TPictureEditor.Edit;

begin

  with TImageForm.Create(nil) do

  try

    ImageDrBob.Picture := TPicture(GetOrdValue);

    if ShowModal = mrOk then

    begin

      if (GetPropType^.Name = 'TPicture') then

        SetOrdValue(LongInt(ImageDrBob.Picture))

      else { Bitmap }

        SetOrdValue(LongInt(ImageDrBob.Picture.Bitmap))

    end

  finally

    Free

  end

end {Edit};

 

procedure Register;

begin

  RegisterPropertyEditor(TypeInfo(TPicture), nil, '', TPictureEditor);

  RegisterPropertyEditor(TypeInfo(TBitmap), nil, '', TPictureEditor)

end;

end.

 

 

unit CompMenu;

interface

uses

DsgnIntf;

 

Type

TCommonDialogComponentEditor = class(TComponentEditor)

  function GetVerbCount: Integer; override;

  function GetVerb(index: Integer): String; override;

  procedure Executeverb(index: Integer); override;

end;

 

TCommonDialogDefaultEditor = class(TDefaultEditor)

  function GetVerbCount: Integer; override;

  function GetVerb(index: Integer): String; override;

  procedure Executeverb(index: Integer); override;

end;

 

procedure Register;

 

implementation

uses

Dialogs;

 

{ TCommonDialogComponentEditor }

 

function TCommonDialogComponentEditor.GetVerbCount: Integer;

begin

  GetVerbCount := 2

end {GetVerbCount};

 

function TCommonDialogComponentEditor.GetVerb(index : Integer): String;

begin

  if Index >= 1 then GetVerb := '&About...'

                else GetVerb := '&Execute ' + Component.ClassName + '...'

end {GetVerb};

 

procedure TCommonDialogComponentEditor.ExecuteVerb(index: Integer);

begin

  if index >= 1 then

    MessageDlg('TCommonDialogComponentEditor (c) 1996 by Dr.Bob',

                mtInformation, [mbOk], 0)

  else

  begin

    if (Component IS TOpenDialog) then { also TSaveDialog }

      (Component AS TOpenDialog).Execute

    else

      if (Component IS TPrintDialog) then

        (Component AS TPrintDialog).Execute

      else

        if (Component IS TPrinterSetupDialog) then

          (Component AS TPrinterSetupDialog).Execute

        else

          if (Component IS TColorDialog) then

            (Component AS TColorDialog).Execute;

    Designer.Modified

  end

end {ExecuteVerb};

 

{ TCommonDialogDefaultEditor }

 

function TCommonDialogDefaultEditor.GetVerbCount: Integer;

begin

  GetVerbCount := 3

end {GetVerbCount};

 

function TCommonDialogDefaultEditor.GetVerb(index : Integer): String;

begin

  case Index of

    0: GetVerb := '&OnEvent handler code';

    1: GetVerb := '&Execute ' + Component.ClassName + '...';

    else GetVerb := '&About...'

  end

end {GetVerb};

 

procedure TCommonDialogDefaultEditor.ExecuteVerb(index: Integer);

begin

  if index >= 2 then

    MessageDlg('TCommonDialogDefaultEditor (c) 1996 by Dr.Bob',

                mtInformation, [mbOk], 0)

  else

  begin

    if (Component IS TFindDialog) then { also TReplaceDialog }

      (Component AS TFindDialog).Execute

    else

      if (Component IS TFontDialog) then

        (Component AS TFontDialog).Execute;

    Designer.Modified

  end

  else inherited Edit { TDefaultEditor.Edit }

end {ExecuteVerb};

 

procedure Register;

begin

  { empty default component editors }

  RegisterComponentEditor(TOpenDialog, TCommonDialogComponentEditor);

  RegisterComponentEditor(TPrintDialog, TCommonDialogComponentEditor);

  RegisterComponentEditor(TPrinterSetupDialog, TCommonDialogComponentEditor);

  RegisterComponentEditor(TColorDialog, TCommonDialogComponentEditor);

  { event default component editors }

  RegisterComponentEditor(TFontDialog, TCommonDialogDefaultEditor);

  RegisterComponentEditor(TFindDialog, TCommonDialogDefaultEditor)

end;

end.