We help IT Professionals succeed at work.

QuickReports ,  add a TQRBand  to TQuickRep at runtime

crestty
crestty asked
on
I am trying to add a
TQrBand to a TQuickReport at runtime.

any sample code will do here.



here is some of my code :

for i := 0 to cnt - 1 do
begin
// create the objects
 sqlObjAr[i] := TQuery.Create(self);
 bandObjAr[i]:= TQRBand.Create(self);
 repObjAr[i] := TQuickRep.Create(self);
 dsObjAr[i]     := TDataSource.Create(self);                  tableObjAr[i]:=TTable.Create(Self);
end;

{then i configure them}


// here are two lines of code that does not work for me
repObjAr[i].AddBand(bandObjAr[i]);
bandObjAr[i] as TQRBand).ParentReport :=repObjAr[i];

{the last step is to have a Composit Report}



Comment
Watch Question

Commented:
All you need is to write the next staring to attach band to the QuickReport:

TQRBand(bandObjAr[i]).Parent := TQuickRep(repObjAr[i]);





Author

Commented:
Vterekh, thank you for the help.

I would like a simple example, where you
have a master detail Report, whereby
all components are created at run-time.


Then extend this runtime report to be a composit report.

Thus having a true flexible report.

here is some code that fails, but should provide you
with a general idea.

 private
    { Private declarations }
    amtOfreps          : Integer;
    sqlObjAr          : array of TQuery;
    bandObjAr          : array of TQRBand;
    repObjAr          : array of TQuickRep;
    dsObjAr               :     array of TDataSource;
    tableObjAr     : array of TTable;
    dbt                         : array of array of     TQRDbText;          // db text
//~~~~~~~~~~~~cut here~~~~~~~~~

procedure TRep1Form1.createSqlObj(cnt: Integer);
var
  i,j: Integer;
  SomeFields: TStringList;
  nIdx: integer;
begin
  amtOfreps     :=     cnt;
  // set the object array dimensions
  SetLength(sqlObjAr, cnt);
  SetLength(bandObjAr, cnt);
  SetLength(repObjAr, cnt);
  SetLength(dsObjAr, cnt);
  SetLength(tableObjAr, cnt);
  SetLength(dbt, cnt,14);

  for i := 0 to cnt - 1 do
  begin
    // create the objects
    sqlObjAr[i]      := TQuery.Create(self);
    bandObjAr[i]     := TQRBand.Create(self);
    repObjAr[i]      := TQuickRep.Create(self);              
    dsObjAr[i]          := TDataSource.Create(self);                                      
    tableObjAr[i]     :=         TTable.Create(Self);                    

    // set the relation ship's of the objs
    // table
          tableObjAr[i].DatabaseName := 'NAV';
    tableObjAr[i].MasterSource := dsObjAr[i];
    tableObjAr[i].TableName := 'G/L per month';
    // set the fields
    with (tableObjAr[i] as TTable) do
       begin
         ReadOnly := True;
         for nIdx := 0 to FieldCount - 1 do
           SomeFields.Add(Fields[nIdx].FieldName);
       end;
    tableObjAr[i].Active := true;

    // data source
          dsObjAr[i].DataSet := sqlObjAr[i];
    // report
    repObjAr[i].DataSet := sqlObjAr[i];


    // Sql is done below


    // create 12 DB Texts ( the months )
    for j := 0 to 11 do
       begin
            dbt[i,j] :=     TQRDbText.Create(self);
       end;

       // set the 12 DBText properties
       CopyObject(QRDBText16,dbt[i][0]);
       CopyObject(QRDBText17,dbt[i][1]);
       CopyObject(QRDBText18,dbt[i][2]);
       CopyObject(QRDBText19,dbt[i][3]);
       CopyObject(QRDBText20,dbt[i][4]);
       CopyObject(QRDBText21,dbt[i][5]);
       CopyObject(QRDBText22,dbt[i][6]);
       CopyObject(QRDBText23,dbt[i][7]);
       CopyObject(QRDBText24,dbt[i][8]);
       CopyObject(QRDBText25,dbt[i][9]);
       CopyObject(QRDBText26,dbt[i][10]);
       CopyObject(QRDBText27,dbt[i][11]);

    // set the band relationships
    for j:=0 to 11 do
    begin
             dbt[i][j].DataSet := tableObjAr[i];
    end;

    // Name Field
    dbt[i,12] :=     TQRDbText.Create(self);
    //CopyObject(QRDBText28,dbt[i][12]);

    dbt[i][12].DataSet     := sqlObjAr[i];
    dbt[i][12].DataField := 'Name';
    dbt[i][12].Left     := 5;
    dbt[i][12].Top     := 0;


    //Total Field
    dbt[i,13] :=     TQRDbText.Create(self);
    dbt[i][13].Dataset      := sqlObjAr[i];
    dbt[i][13].DataField := 'Net Change';
    dbt[i][13].Left := 103;
    dbt[i][13].Top := 0;

    TQRBand(bandObjAr[i]).Parent := TQuickRep(repObjAr[i]);


  end;

end;
//------------------------------------------------------------------------------
// Set the appropiate SQL OBJ's sql statement
procedure TRep1Form1.setSqlOBjQuery(sql: array of string);
var
  i: Integer;
begin
  for i := 0 to Length(sqlObjAr) -1  do
  begin
       sqlObjAr[i].Close;
    sqlObjAr[i].DatabaseName := 'NAV';
    sqlObjAr[i].SQL.Clear;
    sqlObjAr[i].SQL.Add(sql[i]);
    sqlObjAr[i].Open;
  end;
end;









crestty:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept vterekh's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer