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

Replacing / removing of certain components by code

edited February 2012 in General
Hello,

I need to go through my reports and to replace all DBMemos with DBRichTexts.
Those DBMemos can be placed on a band directly, but also in a subreport or
on a region.

Once I find one of the required DBMemos, I create a DBRichText and "clone"
the positions, the properties etc. an detele the DBMemo afterwards.

For components placed on on a band directly, it works fine:

if assigned(ReferenceDBMemo.Band) then begin
NewDBRichText.Band := ReferenceDBMemo.Band;
end;
...
...
myReport.Bands[BandCounter].RemoveObject(ReferenceDBMemo);

Once a component is on a region, it seems to work differently. After
creation of a DBRichText both properties (band and region) are nil.

When I do this:

if assigned(ReferenceDBMemo.Region) then begin
NewDBRichText.Region:= ReferenceDBMemo.Region;
end;

band-property gets assigned automatically, it seems. Is it "enough" or do I
have to assign the band-property manually anyway?

How should the removing of the component work in that case? It seems not to
work, to simply remove the component form the band (as above). Apparently I
need to remove the component from the region first, after this the component
seems to land on the band. So at the moment I'm doing this:

if assigned(NewDBRichText.Region) then begin
TppRegion(NewDBRichText.Region).RemoveObject(ReferenceDBMemo);
end;

myReport.Bands[BandCounter].RemoveObject(ReferenceDBMemo);

Is that correct?

Comments

  • edited February 2012
    Hi Mark,

    Yes, adding or removing a component from a region will also add/remove
    it from the band. This is all that needs to be done when adding or
    removing components from regions.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2012
    Hi Nico,

    it seems to be not enough to remove the component from the region only. I've
    just tried it again and the result is still the same:


    Without this last row the component is still there - just on the band,
    instead of the region.

    Am I doing anything wrong?

  • edited February 2012
    After looking at the source, it appears you are correct. When wanting
    to completely remove an object from a region you will also need to set
    its Band property to nil.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2012
    Ok, thanks Nico :)

This discussion has been closed.