Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:27:37+00:00 2026-06-07T03:27:37+00:00

Using Delphi 2010 and RTTI, I know how to get the class type of

  • 0

Using Delphi 2010 and RTTI, I know how to get the class type of an object and how to get/set the value and type of an object’s properties, but how do you determine which class in the inheritance chain a property came from? I want to use the properties of a base class differently than the main class.

Consider this code:

TClassBase = class(TObject)
published
  property A: Integer;
end;

TClassDescendant = class(TClassBase)
published
  property B: Integer;
end;

procedure CheckProperties(Obj: TObject);
var
  ctx: TRttiContext;
  objType: TRttiType;
  Prop: TRttiProperty;
begin
  ctx := TRttiContext.Create;
  objType := ctx.GetType(Obj.ClassInfo);
  for Prop in objType.GetProperties do begin
    if Prop.GetClassType is TClassBase then
      // do something special with base class properties
    else
      // standard functionality on all other properties
  end;
end;

The problem is there is no GetClassType for the properties. ClassType just returns TRttiInstancePropertyEx instead of the name of the class to which the property belongs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:27:39+00:00Added an answer on June 7, 2026 at 3:27 am

    Another option is use the Parent property of the TRttiProperty, from here you can access to the class which the property is part of.

    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      Rtti,
      SysUtils;
    
    type
      TClassBase = class(TObject)
        private
          FA: Integer;
       published
        property A: Integer read FA;
      end;
    
      TClassDescendant = class(TClassBase)
        private
          FB: Integer;
        published
        property B: Integer read FB;
      end;
    
    procedure CheckProperties(Obj: TObject);
    var
      ctx: TRttiContext;
      objType: TRttiType;
      Prop: TRttiProperty;
    begin
      ctx := TRttiContext.Create;
      objType := ctx.GetType(Obj.ClassInfo);
       for Prop in objType.GetProperties do
       if TRttiInstanceType(Prop.Parent).MetaclassType=TClassBase then
         Writeln(Format('The property %s is declarated in the TClassBase class',[Prop.Name]))
       else
         Writeln(Format('The property %s is not declarated in the TClassBase class',[Prop.Name]))
    end;
    
    
    begin
      try
       //CheckProperties(TClassBase.Create);
       CheckProperties(TClassDescendant.Create);
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
      Readln;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Delphi 2010... I have a set of binary properties I want to group
Is there a way (on windows using Delphi 2010) to get the number of
Possible Duplicate: How to get images from URL in Delphi I'm using Delphi 2010,with
I have started using of generics in Delphi 2010 but I have a problem
Using Delphi 2010, let's say I've got a class declared like this: TMyList =
I am using Delphi 2010 and my program wants to get the system's temp
I am using Delphi 7 but I have trialed the Delphi 2005 - 2010
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
I am using Delphi 2010. I have to set UseLatestCommonDialogs to False and additionally
Using the RTTI system in Delphi 2010, is there any way to find out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.