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

Printing Single Records from a Template

edited February 2002 in General
I am a new user of ReportBuilder and I need someone to point me in the right
direction as I get started. I am converting a program which used Quick
Report Artist. Quick Reports were designed with a separate report designer
and saved to external report templates. These report templates were loaded
at runtime and used to print Contracts, Receipts, Checks, etc. from
information located in single records from seveal different tables.

The approach in Quick Report Artist is to create the template externally
from the program, then load it from a file. The user or application selects
the correct records from the tables, and then in the BeforePrint Event,
components are searched for and then used to point to the correct record for
printing. Sometimes a few calculated fields are searched for in the same
manner and initialized at this point in time to their correct value.

I'm wondering if I should use the same approach in ReportBuilder, or if
there is a different approach that I should use. I am using ReportBuilder
Pro version 6. Following is the code I have in the project that used Quick
Report Artist. ArtLoader1 is the component that loads the report template
and prints it.

procedure TFToolsDM.ArtLoader1BeforePrint(RepForm: TfrmArtLoader;
var CanShow: Boolean);
var
wTable : TTable;
wLabel : TQRLabel;
wQuickRep : TQuickRep;
padsize : integer;
s1 : str255;
begin
if RepForm.GetComponent(TTable,'CustTB',TComponent(wTable),False) then
wTable.GoToCurrent(FToolsDM.CustTB);
if RepForm.GetComponent(TTable,'LoansTB',TComponent(wTable),False) then
wTable.GoToCurrent(FToolsDM.LoansTB);
if RepForm.GetComponent(TTable,'TransTB',TComponent(wTable),False) then
wTable.GoToCurrent(FToolsDM.TransTB);
{Initialize Any Custom Report Labels}
if RepForm.GetComponent(TQRLabel,'LoanAmtInWords',Tcomponent(wLabel),
false) then
wlabel.caption:=CurrencyToWords(
FToolsDM.LoansTB.FieldByName('LoanAmt').AsFloat)+' Dollars';
if RepForm.GetComponent(TQRLabel,'ChkAmtPadded',Tcomponent(wLabel),
false) then
begin
s1:=FormatFloat('#,##0.00',
FToolsDM.LoansTB.FieldByName('LoanAmt').AsFloat);
PadSize:=ChkAmtWidth-length(s1);
if padsize<0 then padsize:=0;if padsize>254 then padsize:=254;
s1:=ChkAmtPrefix+StringOfChar('*',padsize)+s1;
wLabel.Caption:=s1;
end;
if RepForm.GetComponent(TQRLabel,'ChkAmtInWordsPadded',Tcomponent(wLabel),
false) then
begin
s1:=CurrencyToWords(FToolsDM.LoansTB.FieldByName('LoanAmt').AsFloat);
PadSize:=ChkAmtInWordsWidth-length(s1);
if padsize<0 then padsize:=0;if padsize>254 then padsize:=254;
s1:=s1+ChkAmtInWordsSuffix+StringOfChar('*',padsize);
wLabel.Caption:=s1;
{Following Done Inside Finding ChkAmtInWordsPadded So As Not To
Change Printers When Doing Contract}
if ChkPrinter<>'' then
if RepForm.GetComponent(TQuickRep,'QuickRep',Tcomponent(wQuickRep),
false) then
wQuickrep.Printersettings.printerindex:=
printer.printers.Indexof(ChkPrinter); {e.g., 'HP LaserJet 4 on
LPT1:'}
end;
end; {ArtLoader1BeforePrint}

procedure PrintForm(FName : string;NrToPrint : word);
var {Assumes CustomerTB & LoansTB Open And Ready}
i : word; {Assumes TransTB Closed & wTransNo Set}
begin
if (NrToPrint<=0) then exit;
FToolsDM.TransTB.Open;
try
if FToolsDM.TransTB.Locate('TransNo',wTransNo,[]) then
begin
FToolsDM.ArtLoader1.InitialDir:=ReportPath;
FToolsDM.ArtLoader1.FileName:=FName;
FToolsDM.ArtLoader1.UnLoadReport;
{UnLoadReport For Saftey, Not To Print Previous Report}
for i:=1 to NrToPrint do
FToolsDM.ArtLoader1.Print;
end;
finally
FToolsDM.TransTB.Close;
end;
end; {PrintForm}

I greatly appreciate any advice or direction on this. I have read the
documentation and completed the learning tutorial, but it still is not clear
to me how to approach this type of report.

David Miller

Comments

  • edited February 2002
    Hook the report up so that it doesn't have a datapipeline. Set
    Report.AutoStop to True. Now you'll only get one detail band. Inside the
    detail band, you'll need to connect each dbText to a different datapipeline.
    Or, instead of having multiple datapipelines, one for each record, you could
    use a single JITPipeline. Then, based on the field name, you can use a
    separate query for each dbText to retrieve the single necessary record from
    a table. See the JITdemos in the main reports demo project. You'll need to
    define the fields on the datapipeline, and then code the JIT's
    OnGetFieldValue event to handle each field name


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.