Board index » delphi » Problem with creating runtime label in Quickreport

Problem with creating runtime label in Quickreport

Hello,

I try to create run-time a TQRLabel. I do it like this:

var
   aLabel: TQRLabel
begin
    aLabel := TQRLabel.Create{self}
    aLabel.Parent := QRBand1
    aLabel.name := 'lblTest'
    aLabel.top := 12
    aLabel.left := 12
    aLabel.Caption := 'Testing'
end

When I do this, I got a problem with the parent property. Without the
parent property the program runs perfectly, but I don't see the label.
When I use the parent property, I got a acces violation.

Who can help me???

Thanks

Vries...@Iquip.nl

 

Re:Problem with creating runtime label in Quickreport


You would have to do something like the following:

 with TQRLabel(QRBand1.AddPrintable(TQRLabel)) Do
   begin
    Top := 12;
    Left := 12;
    Caption:='Testing';
end;

Re:Problem with creating runtime label in Quickreport


In article <8ja5ql$m...@bornews.borland.com>, l...@municipal-associates.com

Quote
(Les Piotrowski) wrote:
> You would have to do something like the following:

>  with TQRLabel(QRBand1.AddPrintable(TQRLabel)) Do

I believe that AddPrintable is just shorthand for creating the object and
setting its parent in one go.  I have no problems with code like...

procedure TPopularityReport.SetupBand(aBand: TQRCustomBand);
// Create the QRLabels and QRShape lines for the specified band.
var
  aLabel: TQRLabel;
begin
...
    aLabel:=TQRLabel.Create(Self);
    aLabel.Parent:=aBand;
    aLabel.AutoSize:=False;
    aLabel.Caption:=ColumnNames[i];
    // Centre the label vertically within the band.
    aLabel.Size.Top:=(aBand.Size.Height - aLabel.Size.Height) / 2;
    aLabel.Alignment:=taRightJustify;
    aLabel.Size.Left:=colStart + (i * columnPitch);
    aLabel.Size.Width:=columnPitch - 0.1;
...

I think he needs to home in on exactly where the access violation is
occurring, i.e. single stepping to find which line of code is the culprit.

--Bill Sparrow--

Re:Problem with creating runtime label in Quickreport


I already found out what the problem is:

You have to create components runtime in the beforeprint event of the report.
Quickreport only can create components he knows before the report is created.

Quote
Bill Sparrow wrote:
> In article <8ja5ql$m...@bornews.borland.com>, l...@municipal-associates.com
> (Les Piotrowski) wrote:

> > You would have to do something like the following:

> >  with TQRLabel(QRBand1.AddPrintable(TQRLabel)) Do

> I believe that AddPrintable is just shorthand for creating the object and
> setting its parent in one go.  I have no problems with code like...

> procedure TPopularityReport.SetupBand(aBand: TQRCustomBand);
> // Create the QRLabels and QRShape lines for the specified band.
> var
>   aLabel: TQRLabel;
> begin
> ...
>     aLabel:=TQRLabel.Create(Self);
>     aLabel.Parent:=aBand;
>     aLabel.AutoSize:=False;
>     aLabel.Caption:=ColumnNames[i];
>     // Centre the label vertically within the band.
>     aLabel.Size.Top:=(aBand.Size.Height - aLabel.Size.Height) / 2;
>     aLabel.Alignment:=taRightJustify;
>     aLabel.Size.Left:=colStart + (i * columnPitch);
>     aLabel.Size.Width:=columnPitch - 0.1;
> ...

> I think he needs to home in on exactly where the access violation is
> occurring, i.e. single stepping to find which line of code is the culprit.

> --Bill Sparrow--

Other Threads