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 6603157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:58:15+00:00 2026-05-25T18:58:15+00:00

consider this simple code {$APPTYPE CONSOLE} uses Rtti, SysUtils; type {$M+} TFoo = class

  • 0

consider this simple code

{$APPTYPE CONSOLE}

uses
  Rtti,
  SysUtils;

type
  {$M+}
  TFoo = class
  strict private
    class var Field1 : Integer;
    field2 :  Integer;
  private
    field3 :  Integer;
    class var Field4 : Integer;
  end;


Var
    ctx : TRttiContext;
    f   : TRttiField;
begin
  try
    ctx:=TRttiContext.Create;

    for f in ctx.GetType(TFoo).GetFields do
     Writeln(f.Name);


    Writeln('Done');
    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

When you run this, only the field3 is listed. it seems which the RTTI does not support fields which are strict private or class var, So the questions are Is possible access a strict private field of a delphi class using Rtti or another method? and I read the documentation of the RTTI.TRttiType.GetFields method but does mention these restrictions, Exist any paper or article which mentions such limitations?

  • 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-25T18:58:16+00:00Added an answer on May 25, 2026 at 6:58 pm

    I can’t try it right now, but what you seem to need could be GetDeclaredFields instead of GetFields. This should give all (instance) fields of a class but not those of an ancestor class. If you need those too, you’ll have to recursively go up the inheritance chain.

    As I said, I can’t try it right now, so you’ll have to see for yourself if it gives you access to strict private fields as well.

    Update

    Note that in your declaration of TFoo, even you probably didn’t intend it, both Field1 and Field2 are class variables!.

    Just reformat your declaration, and you’ll see what I mean:

      TFoo = class
      strict private
        class var
          Field1: Integer;
          Field2: Integer;
      private
        // etc...
    

    Everything that comes after class var is a class variable, until the compiler encounters var, strict, private, protected, etc. Try this, and you’ll also see Field2 being written:

      TFoo = class
      strict private
        class var 
          Field1: Integer;
        var 
          Field2: Integer;
        // etc...
    

    Alternatively try:

      TFoo = class
      strict private
        Field2: Integer;
        class var 
          Field1: Integer;
        // etc...
    

    This means that GetFields and GetDeclaredFields don’t have any problems with strict private fields. They just don’t return class variables. That makes sense, IMO. Class variables are not members of the object being investigated.

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

Sidebar

Related Questions

Consider this simple example code: <form name=text id=frm1 method=post> <input type=checkbox name=name[] value=1000> Chk1<br>
Consider this sample code: <div class=containter id=ControlGroupDiv> <input onbeforeupdate=alert('bingo 0'); return false; onclick=alert('click 0');return
Consider this: public class TestClass { private String a; private String b; public TestClass()
consider this simple and pointless code. #include <iostream> struct A { template<int N> void
Consider this simple class: package Foo; use Moose; has foo => ( is =>
Analyzing the location.hash with this simple javascript code: <script type="text/javascript">alert(location.hash);</script> I have a difficult
Consider this code: public void actionPerformed(ActionEvent e) { setEnabled(false); new SwingWorker<File, Void>() { private
consider this simple code: echo iconv('UTF-8', 'ASCII//TRANSLIT', 'è'); it prints `e instead of just
consider this simple code: $q=mysql_query('SELECT [...]'); while($row=mysql_fetch_assoc($q)){ //Do something with data //And write how
Let's consider this simple code: <h:form id=myForm> <h:inputText id=myInput> <a4j:support event=onchange actionListener=#{myBean.doSomething}/> </h:inputText> </h:form>

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.