Home Component Writing

Need A Shape Component with 3 test fields

edited March 2003 in Component Writing
I am new at component writing, but I have a seating chart that is in report
builder 6.00 and Deplhi 6, that has 100 seats. A seat is a circle with 3
text fields, Seat Number, Name, and County. I would like to build a Report
Builder component to drop on the report that would be the circle and the 3
fields. The 3 fields would need to be exposed so a program can assign
values to them. Can it be done?

Comments

  • edited March 2003
    One way to try to model this is to create a region descendent that creates a
    TppShape (circle) and three TppDBText components in its constructor. Then
    you can move the region around and the four components in the region will
    automatically move with it. Disable the region's bounding box. You'll have
    to select the different text fields to hook up the data fields from the
    datapipeline in the report designer. At runtime, you may rather define the
    interface on your class for three properties so that you can set the
    datafield names and have them pass through to the three dbTexts. You'll also
    need a data pipeline property to pass through to the dbTexts for the runtime
    interface support you want to use.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    The region idea is a good one. Is there a way to change the shape of the
    region from a square to a circle. It looks like in the code for
    TppCustomRegion there is a procedure to change the shape, but I don't see
    how you would do it.

  • edited March 2003
    Here is an example. You are right, it does require one new protected
    property to set the ShapeType of the TppRegion ancestor from a descendent.
    I've included that change in ppRegion.pas. It won't allow you to use RAP in
    this case because the interface section changed. So the alternative is to
    implement the ellipse change from the descendent code I have in
    TdmRoundRegion and place it in TppRegion in your version of RBuilder\Source
    if you want to use RAP. This is just a work around instead of having to
    create a property to set the FShapeType. The next release of RB will contain
    a the new protected property to support this from a descendent and still be
    able to use RAP.

    http://www.digital-metaphors.com/tips/RoundRegion.zip


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Now that I have this region I need to put 3 labels in the region.
    So, in the circular region, I need 3 labels
    ---------------
    ! Label 1 !
    ! Label 2 !
    ! Label 3 !
    ---------------

    The reason is, I set in an app, the seat numbers, names, and county of 150
    legislators in a seating chart. I'm trying to do this component to
    eliminate the number of compents that it takes to do this. You have a
    TppShape (thecircle), 3 TppLabels (seat number, names, and county) per
    person for a total of 600 compenents. I thought since every seat has the
    same 4 components I could do a component.


    I can get the region to create, but I can't create the label and get them to
    show up. I try setting their Parent and I get this is a read only property.
    I just can't seem to can't the labels to show up, more or less get them to
    show up in the region box and have the region box be the parent of the 3
    labels that need to be there.

    I am open to another way of doing this if this sound totally off.



  • edited March 2003
    You need to set the band property of the labels to the band of the region.
    In order to assign the labels to a region, you need to set the
    TppLabel.Region := myRegion or Self in this case. That should do the trick.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    What am I missing? I did what you said and I got incompatible types.
    TppLabel.Region - is looking for a TppComponent and
    myRegion - is a TComponent.


  • edited March 2003
    I was thinking your TmyRegion is a TppRegion descendent. I'll see if I can
    build an example in which a region creates a label embedded in it.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Maybe it's me. Here is what I am doing.

    {---------------------------------------------------------------------------
    ---}
    {In ppRegion Code the declarations
    }
    {---------------------------------------------------------------------------
    ---}
    TppCustomRegion = class(TppStretchable)
    .....
    TppRegion = class(TppCustomRegion)

    { TppCustomRegion.Create }
    constructor TppCustomRegion.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    CacheRecordSize := SizeOf(TppRegionSaveRec);
    ...
    {---------------------------------------------------------------------------
    ---}
    { TppRegion.Create }
    constructor TppRegion.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    DefaultPropName := 'Caption';
    DefaultPropEditType := etAutoEdit;
    end;
    {---------------------------------------------------------------------------
    ---}
    {---------------------------------------------------------------------------
    ---}


    TppRounedRegion= class(TppRegion)

    constructor TppRounedRegion.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    ShapeType := stEllipse;
    end;

    {---------------------------------------------------------------------------
    ---}
    {---------------------------------------------------------------------------
    ---}

    region I have:

    TppLegisSeat = class(TppRounedRegion)
    private
    FSeatNumber :String;
    FSeatName :String;
    FSeatCo :String;

    FlblSeatNumber :TppLabel;
    FlblSeatName :TppLabel;
    FlblSeatCo :TppLabel;


    constructor TppLegisSeat.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    {create a circle}
    Height := 0.6667;
    Width := 0.6667;

    {Create Name Label}
    FlblSeatName := Tpplabel.Create(self);
    FlblSeatName.Region := ???????????????????;

    What would FlblSeatName.Region be set to?
    aOwner is a TComponent, the ppLegisSeat component is not defined and when
    using self the label never show up.

    I'm still green when it comes to RB components. Thanks for your help.




  • edited March 2003
    My initial tests indicate that adding a component which creates multiple
    embedded components in the report designer can only work if the labels
    cannot be freed from inside the region by the end user. The report designer
    never expects this case when the components are on the same band, unlike a
    subreport which is a embedded subreport. I have a region that creates a
    label, it can be created and deleted in the designer and the designer can be
    shutdown with no destroy bugs. I'll see if I can lock down the labels in the
    region so that they are not deletable as a workaround.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.