Create childband Delphi (QR) at runtime

256 Views Asked by At

I have the following code

procedure Tar_ardemo.qr_ardemoBeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
var
    QR: TquickRep;
    QB2: TQRBand;
    QB3: TQRChildBand;
    QL: TQRLabel;
begin
  with artikste do
  begin
    close;
    sql.Clear;
    sql.add('SELECT * FROM Artikels');
    open;
    first;
  end;

  QR := qr_ardemo;
  QB2 := QRBAND2;
  QB3 := TQRchildband.Create(QR);
  QB3.ParentBand := QB2;
  QB3.Height := 40;

  QL := TQRLabel.Create(QR);
  QL.Parent := QB3;
  QL.Left := 300;
  QL.Top := 1;
  QL.Width := 81;
  QL.Height := 23;
  QL.Caption := 'QRLabeZZ';
end;

I want to create a Childband (QB3) and a QRLabel (QL) at runtime. I just can't see it in my output, when I run the script in Delphi. When I change QL.Parent := QB3 to QB2, I see the output in QRBand2, but I want to see it in the just created Childband QB3. What do I wrong? I can not figure it out.

Thanks

1

There are 1 best solutions below

2
Hans van der Rijst On

This could be a solution:

procedure Tar_ardemo.qr_ardemoBeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
var
    QR: TquickRep;
    QB2: TQRBand;
    QB3: TQRChildBand;
    QL: TQRLabel;
    QS : string;
begin
  with artikste do
  begin
    close;
    sql.Clear;
    sql.add('SELECT * FROM Artikels');
    open;
    first;
  end;

  QR := QR_ARDEMO;
  QB2 := QRBAND2;

  QB2.HasChild := true;
  QB2.ChildBand.Height := 23;
  QL := TQRLabel.Create(QR);
  QL.Parent := QB2.ChildBand;
  QL.Left := 100;
  QL.Top := 1;
  QL.Width := 81;
  QL.Height := 23;
  QL.Caption := 'QRLabeXX';

  QB2.ChildBand.HasChild := true;
  QB2.ChildBand.ChildBand.Height := 23;
  QL := TQRLabel.Create(QR);
  QL.Parent := QB2.ChildBand.ChildBand;
  QL.Left := 100;
  QL.Top := 1;
  QL.Width := 81;
  QL.Height := 23;
  QL.Caption := 'QRLabeYY';

  QB2.ChildBand.ChildBand.HasChild := true;
  QB2.ChildBand.ChildBand.ChildBand.Height := 23;
  QL := TQRLabel.Create(QR);
  QL.Parent := QB2.ChildBand.ChildBand.ChildBand;
  QL.Left := 100;
  QL.Top := 1;
  QL.Width := 81;
  QL.Height := 23;
  QL.Caption := 'QRLabeZZ';
end;

end.

This works (huray). But now the problem is: How do I get an array of childband.chhildband......childband. There is no Childband array like Childband[x]. Or is there one?? As I wrote there could be many Childbands [n]. It has to be dynamic, and... after printing the first childbands, they must be destroyed, before printing the next childbands for the next record (Artikel).