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

How to dynamic create a ppLabel

edited April 2007 in General
Hello

i need help to create a ppLabel dynanicly
i have tryed this, but getting a error, without the "din.Parent:=self;" line
the ppLabel don't show on the report

plz help

public
{ Public declarations }
din : TppLabel;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
din:=TppLabel.Create(self);
/// the next line gives an error
din.Parent:=self;
/// above line give an error
din.Caption:='ff';
din.Top:=10;
din.Left:=10;

end;

Comments

  • edited April 2007
    Hi Brian,

    Do not assign the parent property to Report components. The parent of a
    report component is the band in which they reside and is assigned when the
    Band property is set.

    din:=TppLabel.Create(self);
    din.Band := Report.DetailBand;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2007

    I have a procedure in another unit that every report calls for setup of
    the report. I want to have this setup a label based on a define. I
    get an access error when I try and create the label (aRptLabel).
    (Delphi 2007)



    procedure ReportSetup(rpt: TppReport; frm: TForm);
    var
    aRptLabel: TppLabel;
    begin
    dHeight := rpt.PrinterSetup.PaperHeight;

    with rpt.PageStyle do
    begin
    {$IFNDEF DEMO}
    Height := 0.25;
    Visible := False;
    {$else}
    Height := dHeight;
    Visible := True;
    PageSetting := psAll;
    {$ENDIF}
    end;

    aRptLabel.Create(frm); <<< error

    with aRptLabel do
    begin
    Band := rpt.PageStyle;
    Caption := cDEMO_VERSION;
    Font.Size := 48;
    Angle := 90;
    Font.Color := cDEMO_VERSION_COLOR;
    end;


    any ideas why the access error? the form and the report are passed as
    parameters.


    Thanks,

    Craig






  • edited May 2007
    Hi Craig,

    Trace through your code and be sure the "frm" parameter is valid. Also,
    check the above code to be sure the PageStyle band is not nil before you are
    accessing its properties.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2007

    They are. :) I have more code within this procedure and the form and
    report are valid. Creating this label is creating an AV at runtime.
    It's the only problem I have in this procedure.




  • edited May 2007

    This procedure is called within the BeforePrint event of the report.
    The report form is displayed at AV time but the white canvas is not.




  • edited May 2007
    Hi Craig,

    Oops, sorry I looked at your code so quickly, I did not see the problem
    right away :).

    Before you can use aRptLabel, you need to create a TppLabel instance and
    assign the aRptLabel variable to it. This is done by calling the class
    Create method.

    aRptLabel := TppLabel.Create(frm);

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2007

    Nico,

    That's okay. I have been looking at it for much longer and couldn't
    see it.

    Thanks, that was it.

    Craig



This discussion has been closed.