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

Deleting report components

edited April 2005 in General
I have created a unit that has a procedure to create a standard header when
passed a HeaderBand. It creates all the labels, lines, memos, etc. on the
header (which is passed as a variable). This works great!

The problem comes in the fact that is the landscape changes and the report
is regened I want to delete all of the components and recreate them in new
positions or find the component and move it if need be. The code for the
CreateHeader procedure (simplified to a single component) can be seen below
...

I have tried a number of ways to delete the components in the header but no
matter what I do, it still tells me a component named "HeaderImage" already
exists.

Some of the things I have tried are:

if HB.ComponentCount > 0 then
for x := HB.ComponentCount - 1 downto 0 do
HB.RemoveComponent(HB.Components[x]);
(ComponentCount is 0 before and 0 after this)
and

if HB.ObjectCount > 0 then
for x := HB.ObjectCount - 1 downto 0 do
HB.RemoveObject(HB.Objects[x]);
(ObjectCount is 19 before and 0 after this)
and

if HB.ChildCount > 0 then
for x := HB.ChildCount - 1 downto 0 do
HB.RemoveChild(HB.Children[x]);
(ChildCount is 0 before and 0 after this)
I have even tried
TempImage := HB.FindComponent('HeaderImage') as TppImage;
if TempImage = nil then TempImage := TppImage.Create(HB);
but TempImage is always nil!

Any help would be greatly appreciated.

Mark Greenhaw


--------------------------------------Code
Begins------------------------------------------
procedure CreateHeader (var HB: TppHeaderBand; PageWidth: double; FontSize:
integer);
const
FontName = 'Arial';
var
TempImage: TppImage;
begin
// Create the header image.
TempImage := TppImage.Create(HB);
TempImage.Band := HB;
TempImage.AutoSize := False;
TempImage.Center := True;
TempImage.Height := 1.1458;
TempImage.Left := 0;
TempImage.MaintainAspectRatio := True;
TempImage.ReprintOnOverFlow := False;
TempImage.ShiftWithParent := False;
TempImage.Stretch := True;
TempImage.Top := 0;
TempImage.Transparent := False;
TempImage.UserName := 'HeaderImage';
TempImage.Visible := True;
TempImage.Width := 1.1458;
TempImage.Name := 'HeaderImage';
end;

Comments

  • edited April 2005
    Hi Mark,

    1. See the article below on the proper way to loop through all the objects
    in a report.

    2. ReportBuilder 9 includes a new Anchor feature for every component which
    allows you to anchor an object to a single side or two adjascent sides of a
    report keeping it in that position relative to that boundary even if the
    size of the report changes. Using this feature may remove the need to
    reposition all your objects manually.

    ----------------------------------------------
    Tech Tip: Loop Thru All Objects in a Report
    ---------------------------------------------

    A ReportBuilder report is composed of a set of components. The basic
    structure is

    Reports.Bands[].Objects[]

    The bands and objects within the report can be accessed directly by object
    name or via the Bands and Objects array properties.

    Below is an example of using the Bands and Objects array properties to
    change the font for all objects on a report.


    uses
    ppClass;


    procedure AssignFontToReport(aFont: TFont; aReport: TppCustomReport);
    var
    liBand: Integer;
    liObject: Integer;
    lObject: TppComponent;

    begin

    for liBand := 0 to aReport.BandCount-1 do

    for liObject := 0 to aReport.Bands[liBand].ObjectCount-1 do
    begin
    lObject := aReport.Bands[liBand].Objects[liObject];

    if lObject.HasFont then
    lObject.Font := aFont;

    end;

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.