Creating Shapes at run time
Hi there,
I'm hoping someone can help. I'm trying to create rectangles at run time
but am not sure which properties are required. I have the shape reacted,
the band set the type of shape, pen color, brush color and style, the top
width, left and visible set to true. What am I missing?
Thanks for your help
Denise
I'm hoping someone can help. I'm trying to create rectangles at run time
but am not sure which properties are required. I have the shape reacted,
the band set the type of shape, pen color, brush color and style, the top
width, left and visible set to true. What am I missing?
Thanks for your help
Denise
This discussion has been closed.
Comments
The minimum amount of code needed to add a shape to a report at runtime is
to create the shape component and assign the Band property. When are you
creating the shape (ie. which event)? Are you loading reports from
templates? Be sure that your Left and Top mesurements are in the report
units and are located in a visible area.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I'm using the BeforePrint event of the band. No they're not from templates.
When you say report units do you mean I have to use the ppShape.spTop := 2.
or ppShape.Top := 2
The reason I'm doing this is that I need to create a diagram that passes in
parameters to represent the height, width etc of the rectangles. I dont
think are possible with the chart component.
The Band.BeforePrint fires too late to add a component to a band. You have
two options to work around this issue. First, you can creat the shape
either in the Report.BeforePrint event or simply before calling
Report.Print. Second, you can manually create the shape draw commands and
draw them to the report page at runtime. This is a little trickier being
that you will have to add the shape to an entire page using report units
(microns). Below is a little snip of code I just made that adds a square to
a report using the DetailBand AfterPrint event.
procedure TForm1.ppDetailBand1AfterPrint(Sender: TObject);
var
lDrawShape: TppDrawShape;
begin
lDrawShape := TppDrawShape.Create(nil);
lDrawShape.Page := ppReport1.Engine.Page;
lDrawShape.Left := ppReport1.PrinterSetup.PageDef.mmMarginLeft;
lDrawShape.Top := ppReport1.PrinterSetup.PageDef.mmMarginTop;
lDrawShape.Width := 30000;
lDrawShape.Height := 30000;
lDrawShape.Pen.Color := clBlack;
lDrawShape.Brush.Color := clBlack;
end;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I've tried setting the ppShape.Units := utInches but it still converts the
Height property to pixels. Is there some way around this?
By default, ReportBuilder will use the pre-defined report units to make
measurements (which are all converted into thousandths of milimeters or
microns before generation). You can change the report units by right
clicking over the rulers that surround each band. Also, you may want to
check out the ppUtils.pas file which contains a bunch of useful methods for
converting measurements. For instance, the ppFromScreenPixels function will
convert any screen pixel value to a different measurement type.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com