Jump to content
Sign in to follow this  
Lars Fosdal

RTTI and record consts?

Recommended Posts

Is there a way to use RTTI for records to allow walking public consts and types to extract names and values?

Asking for a friend 😛 - kidding ... I'm try to produce documentation of certain structures at run time, and would like to do something like TDocBuilder.WalkRecordType<html>.

 

type
  html = record
  type
    TRow = TArray<string>;
  public const
    LineBreak  = '<BR />';
    nbsp   = ' ';
    lt     = '<';
    gt     = '>';
    DivEnd = '</div>';

  public type
    divStyleDefault = record
      public const
        info     = 'info';
        book     = 'book';
        chapter  = 'chapter';
        section  = 'section';
        detail   = 'detail';
        example  = 'example';
        jsoncode = 'jsoncode';
    end;
    
    divStyleDebug = record
      public const
        info     = 'debuginfo';
        book     = 'debugbook';
        chapter  = 'debugchapter';
        section  = 'debugsection';
        detail   = 'debugdetail';
        example  = 'debugexample';
        jsoncode = 'debugjsoncode';
    end;
  {$ifdef debug}
    divStyle = divStyleDebug;
  {$else}
    divStyle = divStyleDefault;
  {$endif}
  end;

 

Share this post


Link to post

No, consts are consts and no types (even if nested in types) hence no RTTI

 

Whatever you are trying you are probably better using something like DelphiAST and include that into your build process to generate something from source.

Edited by Stefan Glienke

Share this post


Link to post

It's too complex for that, as the variations are many and loosely coupled.

It means I will have to handcraft more info manually.

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
Sign in to follow this  

×