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

Information

edited January 2007 in Component Writing
Hi
Im currently making a component it works fine.

What I want to know is how I can class my properties togheter I used :

TppPropertyCategoryManager.PropertyCategories.Add('MyCategory',
'MyProperty');

It works fine but I want to make it a bit further something like TppFont
emulate a record property

My other concern is about RTTI I have a class that need more parameters in
his constructor I used the code from ConstructorToRec in GetPropRec

ie I need MyClass.Create(AOwner : TComponent; ACaption : String);

I tried to do this in GetPropRec

If ppEqual(aPropName, 'Create') Then
Begin
MethodToRec(aPropName, True, aPropRec);

aPropRec.ClassType := THSScript;
aPropRec.Params.AddParam('Class', daClass, THSScript, '', False, False);

aPropRec.Params.AddParam('Result', daClass, nil, '', False, False);

aPropRec.Params.AddParam('Caption', daString, Nil, '', False, False);

aPropRec.IsConstructor := True;
End

and I have this in CallMethod

If ppEqual(aMethodName, 'Create') Then
Begin
RetClass := THSScript.Create(Nil);
aParams.SetParamValue(1, Integer(RetClass));
End

No matter where I put the parameter Caption I can use it in the Report
Designer

Comments

  • edited January 2007

    1. In the VCL and ReportBuilder it is quite common to group some properties
    into a separate class. Examples are TFont, TppPrinterSetup,
    TppEmailSettings, etc. Create a class that descends from TPersistent.
    Declare some published properties. Override the Assign method so that it
    can/assign copy the properties. For examples, see TFont, or in RB see
    TppPrinterSetup, TppEmailSettings, etc.

    Example (psuedo code):

    TmySettings = class(TPeristent)
    public
    Assign(Source: TPersistent); override;
    published
    property Enabled: Boolean;
    property Width;
    end;


    TMyComponent
    published
    property mySettings: TMySettings read FMySettings write SetMySettings:
    end;

    Note: in the above, implement SetMySettings to call TmySettings.Assign


    2. For an example of adding a parameter to a constructor see
    TraTComponentRTTI.GetPropRec and TraTComponentRTTI.GetParams, and
    TraTComponentRTTI.CallMethod in ppRTTI.pas



    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.