TRttiRecordType (Delphi)

From RAD Studio XE2 Code Examples
Jump to: navigation, search

Language:

Versions:

Contents

Description

This example shows how to get the RTTI available for records methods.

Code

program Program1;
 
{$APPTYPE CONSOLE}
 
uses
  SysUtils,
  Rtti;
 
type
  TKey = record
  private
    FData: array[0..15] of Byte;
  public
    function GetByte(Index: Integer): Byte;
    // ...
  end;
 
function TKey.GetByte(Index: Integer): Byte;
begin
  // ...
end;
 
var
  LContext: TRttiContext;
  LType: TRttiType;
  LRecord: TRttiRecordType;
  LMethod: TRttiMethod;
 
begin
  LContext := TRttiContext.Create;
 
  LType := LContext.GetType(TypeInfo(TKey));
  if LType.IsRecord then
  begin
    LRecord := LType.AsRecord;
 
    { List all TKey methods }
    for LMethod in LRecord.GetMethods do
    begin
      Writeln(LMethod.ToString);
    end;
  end;
 
  LContext.Free;
 
end.

Console Output

function GetByte(Index: Integer): Byte

Uses

Personal tools
Previous Versions