Jump to content
egroups

Finding duplicate properties in classes

Recommended Posts

Is anyway how can get list all classes in project,inherited from specific class and have specific property?

By refactoring I can clear properties in descendant,which is defined in parent class.

Share this post


Link to post

maybe my sample can help you to start...

implementation

{$R *.dfm}

uses
  System.Rtti,
  Unit2;

procedure TForm1.Button1Click(Sender: TObject);
var
  LCtx       : TRttiContext;
  LType      : TRttiType;
  LProp      : TRttiProperty;
  LPropParent: string;
begin
  LCtx := TRttiContext.Create;
  for LType in LCtx.GetTypes do
    begin
      if (LType.TypeKind = tkClass) { TRttiInstanceType } and                      { }
        (LType.IsInstance) and                                                     { }
        (LType.AsInstance.MetaclassType.InheritsFrom(TMyClassXXXX { myClass } ) or { }
        LType.AsInstance.MetaclassType.InheritsFrom(TForm { myClass } )) then
        begin
          Memo1.Lines.Add(slinebreak +                       { }
            LType.Name + ', ' +                              { }
            LType.AsInstance.MetaclassType.UnitName + ', ' + { }
            LType.AsInstance.MetaclassType.UnitScope);
          //
          for LProp in LType.GetProperties do
            if (LProp.Name = 'Width' { myPropetyName } ) then
              begin
                LPropParent := 'Parent=nil';
                //
                if (LProp.Parent <> nil) then
                  LPropParent := 'Parent=' + LProp.Parent.ToString;
                //
                Memo1.Lines.Add('..... property: ' + LProp.Name + ', ' + LPropParent);
              end;
        end;
    end;
end;

    image.thumb.png.a6ee60432891fbc8a4bd746ec7688fe2.png

 

Edited by programmerdelphi2k
  • Like 1

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

×