Jump to content
Cobalt747

Can't set Property Editor for Set or Enum

Recommended Posts

It seems like they don't registered.

Am i doing something wrong?

There are no errors, just don't work

Code is really simple:

unit Component1;

interface

uses
  System.SysUtils, System.Classes;

type
  TTestValue = (AFirst, ASecond);
  TTestValues = set of TTestValue;

  TComponent1 = class(TComponent)
  private
    { Private declarations }
    FMySet: TTestValues;
    FFiled1: TTestValue;
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
    property Field1: TTestValue read FFiled1 write FFiled1;
    property MySet: TTestValues read FMySet write FMySet stored false;
  end;

implementation

end.


unit untRegUnit;

interface

Uses
  Classes, DesignIntf, DesignEditors, Component1;

procedure Register;

implementation

type
  TMySetProperty = class(TSetProperty)
  public
    function GetValue: string; override;
  end;

  TMyEnumProperty = class(TEnumProperty)
  public
    function GetValue: string; override;
    procedure SetValue(const Value: string); override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

{ TMySetProperty }

function TMySetProperty.GetValue: string;
begin
  Result := inherited GetValue + '_Test';
end;

{ TMyEnumProperty }

function TMyEnumProperty.GetValue: string;
begin
  Result := inherited GetValue + '_Test';
end;

procedure Register;
begin
  RegisterComponents('Samples1', [TComponent1]);
//  UnlistPublishedProperty(TComponent1, 'Field1');
//  UnlistPublishedProperty(TComponent1, 'MySet');
  RegisterPropertyEditor(TypeInfo(TTestValues), TComponent1, 'MySet', TMySetProperty);
  RegisterPropertyEditor(TypeInfo(Boolean), TComponent1, 'Field1', TMyEnumProperty);
end;

procedure TMyEnumProperty.GetValues(Proc: TGetStrProc);
begin
  Proc('111');
  Proc('222');
end;

procedure TMyEnumProperty.SetValue(const Value: string);
begin
  //inherited;
  SetOrdValue(0);
end;

end.

 


 

Share this post


Link to post
50 minutes ago, Cobalt747 said:

It seems like they don't registered.

Am i doing something wrong?

There are no errors, just don't work

What are you trying to accomplish, exactly?  Do the default property editors work correctly without registering your custom editors?

50 minutes ago, Cobalt747 said:

RegisterPropertyEditor(TypeInfo(Boolean), TComponent1, 'Field1', TMyEnumProperty);

 

Why are you registering the editor for Boolean instead of TTestValue?

Edited by Remy Lebeau

Share this post


Link to post

Remy, you are right, that was a mistake with Field1. After correction, the property work as planned (just a proof of concept)

 

Anyway, property editor didn't work for Set

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×