Replacing / removing of certain components by code
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?
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?
This discussion has been closed.
Comments
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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?
to completely remove an object from a region you will also need to set
its Band property to nil.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com