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

  • Home
  • SEARCH
  • 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 4615148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:47:54+00:00 2026-05-22T01:47:54+00:00

Check this simplified sample (the real scenario is different), I want to set tne

  • 0

Check this simplified sample (the real scenario is different), I want to set tne value of a nested property of a object, in this case set the color of the Font for a TLabel component to clRed using RTTI.

var
  p : TRttiProperty;
  p2: TRttiProperty;
  c : TRttiContext;
begin
   c := TRttiContext.Create;
   try
     p := c.GetType(Label1.ClassInfo).GetProperty('Font');
     p2 := c.GetType(p.PropertyType.Handle).GetProperty('Color');
     p2.SetValue(p.PropertyType.AsInstance,clred); //this line is not working
   finally
     c.Free;
   end;
end;

also i tried

p2.SetValue(Label1,clred);
  • 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-05-22T01:47:54+00:00Added an answer on May 22, 2026 at 1:47 am

    The following code will work.

    var
      p : TRttiProperty;
      p2: TRttiProperty;
      c : TRttiContext;
    begin
       c := TRttiContext.Create;
       try
         p := c.GetType(Label1.ClassInfo).GetProperty('Font');
         p2 := c.GetType(p.PropertyType.Handle).GetProperty('Color');
         p2.SetValue(p.GetValue(Label1).AsObject,clred); //this line now works.
       finally
         c.Free;
       end;
    end;
    

    You need to get the Embedded Font from the Label. TRttiProperty deal with types and not instances. You need to call GetValue() or SetValue() to deal with the instance.

    Your original code was referencing the type and not the instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I make new project and simplified it to check if this bug is real,
Please check this: http://img62.imageshack.us/img62/3598/ieff.png why is it more height than in FF.. i want
My build scenario is like this (simplified): Compile Package (*.zip) Deploy to test environment
I have been given a task that can be simplified to this scenario: Customers
check this out: template <class T> class Test: public T { public: void TestFunc()
check this example: > a = matrix(1:9, nrow = 3, ncol = 3, dimnames
Check this code (My Custom Keyboard): -(IBAction) updateTextBackSpace:(id)sender { if([txtview.text length]>0) { NSString *deletedLastCharString
Check this link! I am having the hardest time trying to figure out why
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
Please check this code out it compiles and runs absolutely fine.. The question is

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.