Thema: Delphi TPropertyEditor Frage

Einzelnen Beitrag anzeigen

Benutzerbild von MaBuSE
MaBuSE

Registriert seit: 23. Sep 2002
Ort: Frankfurt am Main (in der Nähe)
1.837 Beiträge
 
Delphi 10 Seattle Enterprise
 
#7

Re: TPropertyEditor Frage

  Alt 22. Sep 2006, 15:58
Zitat von Neutral General:
Mhh keiner da der mir grad helfen kann ?
Warum, steht doch alles oben.
Weitere Infos und sehr schöne Beispiele (z.B. von mir) findest Du in der DP -> suchen.

z.B. http://www.delphipraxis.net/internal...=531454#531454

Aber ich will ja mal nicht so sein

Hier ein Beispiel, das alle Fragen beantworten sollte.
(Habe keine Kommentare eingefügt, sollte aber zu verstehen sein)

Die 2 Dateien in ein Package packen und installieren.

TPropEditorComponent hat 3 Eigenschaften des selben Typs TMyProperty
aber drei verschiedene Arten die im Objektinspecktor anzuzeigen.

Im Quellcode lässt sich das ganze natürlich gleich ansprechen. Die Property Editoren sind ja nur für die GUI.
Delphi-Quellcode:
PropEditorComponent1.MyPropertyEins.SuperDuper := 'XXX';
PropEditorComponent1.MyPropertyZwei.SuperDuper := 'XXX';
PropEditorComponent1.MyPropertyDrei.SuperDuper := 'XXX';
Delphi-Quellcode:
unit PropEditorComponent;

interface

uses
  SysUtils, Classes;

type
  TMyProperty = class(TPersistent)
  private
    FSuperDuper: string;
    FZahl: Integer;
  published
    property SuperDuper: string read FSuperDuper write FSuperDuper;
    property Zahl: Integer read FZahl write FZahl;
  end;

  TMyPropertyEins = class(TMyProperty);
  TMyPropertyZwei = class(TMyProperty);
  TMyPropertyDrei = class(TMyProperty);

  TPropEditorComponent = class(TComponent)
  private
    { Private-Deklarationen }
    FMyProperty1: TMyPropertyEins;
    FMyProperty2: TMyPropertyZwei;
    FMyProperty3: TMyPropertyDrei;
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published-Deklarationen }
    property MyPropertyEins: TMyPropertyEins read FMyProperty1 write FMyProperty1;
    property MyPropertyZwei: TMyPropertyZwei read FMyProperty2 write FMyProperty2;
    property MyPropertyDrei: TMyPropertyDrei read FMyProperty3 write FMyProperty3;
  end;

implementation

{ TPropEditorComponent }

constructor TPropEditorComponent.Create(AOwner: TComponent);
begin
  inherited;
  FMyProperty1 := TMyPropertyEins.Create;
  FMyProperty1.SuperDuper := 'DP';
  FMyProperty1.Zahl := 2006;
  FMyProperty2 := TMyPropertyZwei.Create;
  FMyProperty2.SuperDuper := 'DP';
  FMyProperty2.Zahl := 2006;
  FMyProperty3 := TMyPropertyDrei.Create;
  FMyProperty3.SuperDuper := 'DP';
  FMyProperty3.Zahl := 2006;
end;

destructor TPropEditorComponent.Destroy;
begin
  FMyProperty3.Free;
  FMyProperty2.Free;
  FMyProperty1.Free;
  inherited;
end;

end.
und

Delphi-Quellcode:
unit PropEditorComponent_dsgn;

interface

uses
  SysUtils, Classes, Dialogs, PropEditorComponent, DesignIntf, DesignEditors;

type
  TMyPropertyEditorEins = class(TClassProperty)
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
  end;

  TMyPropertyEditorZwei = class(TClassProperty)
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Beispiele', [TPropEditorComponent]);
  RegisterPropertyEditor(TypeInfo(TMyPropertyEins), nil, '', TMyPropertyEditorEins);
  RegisterPropertyEditor(TypeInfo(TMyPropertyZwei), nil, '', TMyPropertyEditorZwei);
end;

{ TMyPropertyEditor1 }

function TMyPropertyEditorEins.GetAttributes: TPropertyAttributes;
begin
  Result := [];
end;

function TMyPropertyEditorEins.GetValue: string;
var
  s: string;
begin
  // Nein, so macht man das besser nicht :-), ist ja nur zur Demo
  s := 'SuperDuper="'+TMyProperty(GetOrdValueAt(0)).SuperDuper+'", Zahl='+IntToStr(TMyProperty(GetOrdValueAt(0)).Zahl);
  FmtStr(Result, '(%s)', [s]);
end;


{ TMyPropertyEditorZwei }

procedure TMyPropertyEditorZwei.Edit;
begin
  // Nein, so macht man das besser nicht :-), ist ja nur zur Demo
  ShowMessage('SuperDuper="'+TMyProperty(GetOrdValueAt(0)).SuperDuper+'", Zahl='+IntToStr(TMyProperty(GetOrdValueAt(0)).Zahl));
end;

function TMyPropertyEditorZwei.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog];
end;

function TMyPropertyEditorZwei.GetValue: string;
begin
  FmtStr(Result, '(%s)', ['Abrakadabra']);
end;

end.
(°¿°) MaBuSE - proud to be a DP member
(°¿°) MaBuSE - proud to be a "Rüsselmops" ;-)
  Mit Zitat antworten Zitat