Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

Rtti

Intercept Fields and Props of TObject models without creating Rtti Contexts

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

RttiInterceptor

TRttiInterceptor is a single way to intercept Rtti Fields and Props. It will iterate trought all fields and properties of any TObject without creating rtti context.

/Samples has a small demonstration of the Interceptor Power. In Sample1 we Map any TObject with many primitive type fields, using TValueListEditor as User Interface.

Usage

First you need to create a Class to represent your Model

delphi
  TOrder = class
    Id          : SERIAL;
    CustomerId  : VARCHAR;
    EmployeeId  : Integer;
    OrderDate   : TIMESTAMP;
    Freight     : Currency;
  end;

Then you can extract run time type information using RTTI. To Map all fields with values using Memo it's an example

delphi

uses RttiInterceptor;

procedure Button1Click(Sender: TObject);
begin
  TRttiInterceptor<TOrder>.MapField(
    procedure (AField: TRttiField)
    begin
      Memo1.Lines.Add(format('%-20s %s', [AField.Name, AField.FieldType.ToString]));
    end);
end;