Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Custom RTTI class problems

edited July 2013 in RAP
I want to be instantiate one of my on classes (TnxAvailability) in RAP,
so I have implemented ...

TAvailabilityRTTI = class(TraTObjectRTTI)
public
class procedure GetPropList(aClass : TClass; aPropList :
TraPropList); override;
class function GetPropRec(aClass : TClass; const aPropName :
String; var aPropRec : TraPropRec) : Boolean; override;
class function GetParams(const aMethodName : String) :
TraParamList; override;
class function CallMethod(aObject : TObject; const aMethodName :
String; aParams : TraParamList; aGet : Boolean) : Boolean; override;
class function RefClass : TClass; override;
end;

However, the class factory design of TraTObjectRTTI.CallMethod is such
that my actual TnxAvailability.create method never gets called when I do
something like ..

lAvailabilityRTTI := TAvailabilityRTTI.create;

...in a Report's OnCreate RAP event.

Now, before you ask for a sample project, I can confirm that if I change
this to ..

lraTppPrinterRTTI := TraTppPrinterRTTI.create;


.. then TppPrinter.Create never gets called either. Is this a design
flaw or am I not understanding something fundamental about implemented
custom classes in RAP?

Thanks,

Paul.

Comments

  • edited July 2013
    Hi Paul,

    There should be no need to create a local instance of an RTTI class.

    The purpose of the RAP RTTI classes is to give RAP access to any public
    routines and properties that are defined and implemented in the RTTI
    routines (CallMethod, GetPropRec, GetPropValue, SetPropValue, etc.).
    Once you have the class created and routines implemented, you need to
    register the RTTI class with the RTTI class registry. When the class is
    registered, RAP will be able to recognize the class type when it is used
    and call the correct routines in your new class.

    For instance, in the ppPrintr.pas file at the bottom in the
    initialization section, you will see where the RTTI class is registered.

    raRegisterRTTI(TraTppPrinterRTTI);

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2013
    Thanks for the reply Nick. I had done the correct stuff with registering
    my RTTI class, and its been a while since I've done this so, yes, I
    screwed up and was instantiating the RTTI instead of the class it wraps;
    but I'd also not implemented the construction on my class in
    TAvailabilityRTTI.CallMethod(). Cheers for pointing me in the right
    direction.

    Paul


This discussion has been closed.