Dynamically Assigned Events Not Firing on subreports
Im using RB5.56 - i store all my reports in the database and when the user
chooses a report to print ill pull the report out and dynamically assign a
function the the report's subreport beforeprint event. In this event i
dynamically set lablels and memo fields text. This event is fired 90% and
everything works really well. but every once in a while the event does not
seem to fire and the user has to shut down my delphi app and restart for the
printing to work correctly again. I can not reproduce the error on my
development machine while trying to debug the problem - it only happens on
the users machines and randomly so its very hard to pin down. here is a
large block of code showing how i pull the report out of the DB and assign
the function to the subreports beforePrint event. Hopefully this makes sense
and any help is greatly appreciated
-- Matt
its a ton of code i know but im hurting here - the first function is what is
fired when the users chooses to print - the second function is the
beforePrint fucntion that is assigned to the before print event for the sub
report
procedure TflightWorksheetForm.CharterQuote1Click(Sender: TObject);
var
lPrintDevice: tppprinterdevice;
bandIndex : integer;
objectIndex : integer;
temp : variant;
wasFiltered : boolean;
reportList : TStringList;
subReport : TppChildReport;
bandIndex : integer;
objectIndex : integer;
begin
screen.cursor := crHourglass;
if not flightInfoDataModule.flightLegQuery.filtered then begin
wasFiltered := false;
btnHideCancelledClick(Self);
end
else
wasFiltered := true;
OpenDBObjects;
//create the report object
flightReport := TflightReport.Create(Self);
reportBuilderDataModule.reportTemplateTable.close;
reportBuilderDataModule.reportTemplateTable.open;
flightReport.Template.DatabaseSettings.DataPipeline :=
reportTemplatesPipeline;
flightReport.template.DatabaseSettings.NameField := 'report_name';
flightReport.template.DatabaseSettings.TemplateField :=
'report_template';
flightReport.template.DatabaseSettings.Name := 'charterQuote';
flightReport.template.LoadFromDatabase;
carrierItinerary := false;
printManifest := false;
//set the flight leg band before print
reportList := tstringlist.Create();
flightReport.GetSubReports(reportList);
subReport :=
TppChildReport(reportList.objects[reportList.indexof('flightLegReport:
flightLegPipeline')]);
subreport.ObjectByName(bandIndex, objectIndex, 'lblTime');
subreport.bands[bandIndex].BeforePrint := flightLegBandBeforePrint;
reportlist.free;
//set the footer before print
flightReport.ObjectByName(bandIndex,objectIndex,'lblSignature');
flightreport.Bands[bandIndex].BeforePrint := footerBandBeforePrint;
//set the report before print and after print
flightReport.BeforePrint := flightReportBeforePrint;
SetAddressIndexes;
//set the quote fields
flightReport.ObjectByName(bandindex, objectindex, 'lblQuote');
if trim(txtQuickQuote.text) = '' then
temp := ''
else
temp:= '$' + FormatFloat('#,##0.00',strtofloat(txtQuickQuote.text));
flightReport.Bands[bandindex].objects[objectindex].settext(temp);
flightReport.ObjectByName(bandindex, objectindex, 'lblTax');
flightReport.Bands[bandindex].objects[objectindex].settext('+ ' +
floattostr(globalTax * 100) + '% Federal Excise Tax');
useTailNumber := false;
/////set the printer and print///////////////////
lPrintDevice := tppprinterdevice.Create(Self);
lPrintDevice.Publisher := flightReport.Publisher;
flightReport.PrintToDevices;
lPrintDevice.Free;
//flightReport.print;
//////////////////////////////////
flightReport.Free;
if not wasFiltered then btnShowCancelledClick(Self);
screen.cursor := crArrow;
end;
procedure TflightWorksheetForm.flightLegBandBeforePrint(Sender: TObject);
var
tailNumber : variant;
temp : variant;
tempString : string;
timeString : string;
position : integer;
tempTail : string;
bandIndex : integer;
objectIndex : integer;
subReport : TppChildReport;
reportList : TStringList;
index : integer;
str : string;
vari : variant;
flilegId : variant;
dataSet : TADOQuery;
begin
reportList := tstringlist.Create();
flightReport.GetSubReports(reportList);
if carrierItinerary then begin
subReport :=
TppChildReport(reportList.objects[reportList.indexof('flightLegReport:
flightLegsForCarrierPipeline')]);
dataSet := flightInfoDataModule.flightLegsForCarrierQuery;
end
else begin
subReport :=
TppChildReport(reportList.objects[reportList.indexof('flightLegReport:
flightLegPipeline')]);
dataSet := flightInfoDataModule.flightLegQuery;
end;
tailNumber := dataSet['tail_number'];
//get the indexes for lblDepart
subReport.ObjectByName(bandIndex, objectIndex, 'lblDepart');
if useTailNumber then begin
if tailNumber = Null then begin
temp := dataSet['departString'];
tempString := temp;
subReport.bands[bandindex].objects[objectindex].SetText(pchar(tempString + '
TBA'));
tempTail := 'TBA';
end
else begin
tempTail := tailNumber;
temp := dataSet['departString'];
tempString := temp;
subReport.bands[bandindex].objects[objectindex].SetText(pchar(tempString));
end;
end
else begin
temp := dataSet['departQuoteString'];
tempString := temp;
subReport.bands[bandindex].objects[objectindex].SetText(pchar(tempString));
end;
//print out the start time
temp := dataSet['flileg_start_time'];
//get the indexes for lblTime
subReport.ObjectByName(bandIndex, objectIndex, 'lblTime');
if temp <> Null then begin
timeString := temp;
position := AnsiPos(':', timeString);
timeString := copy(timestring, (position-2), 7);
subReport.bands[bandindex].objects[objectindex].settext(timeString);
end
else
subReport.bands[bandindex].objects[objectindex].settext('');
//print out the end time
temp := dataSet['flileg_end_time'];
//get the indexes for lblEndTime
subReport.ObjectByName(bandIndex, objectIndex, 'lblEndTime');
if temp <> Null then begin
timeString := temp;
position := AnsiPos(':', timeString);
timeString := copy(timestring, (position-2), 7);
subReport.bands[bandindex].objects[objectindex].settext(timeString);
end
else
subReport.bands[bandindex].objects[objectindex].settext('');
//figure out if there are multiple tail numbers
//get the indexes for lblTailNumber
if useTailNumber then begin
flightreport.ObjectByName(bandIndex, objectIndex, 'lblTailNumber');
if flightLegCount = 0 then begin
tailNumber := tempTail;
flightreport.bands[bandindex].objects[objectindex].settext(tailNumber);
flightLegCount := 1;
end
else begin
if tailNumber = Null then tailNumber := '';
if trim(tempTail) <> trim(tailNumber) then
flightreport.bands[bandindex].objects[objectindex].settext('See Below');
end;
end;
if printManifest then begin
flilegId := dataSet['flileg_id'];
flightInfoDataModule.passengerManifestQuery.close;
flightInfoDataModule.passengerManifestQuery.Parameters.items[0].value :=
flilegId;
flightInfoDataModule.passengerManifestQuery.open;
index := 0;
str := '';
while index <
flightInfoDataModule.passengerManifestQuery.RecordCount do
begin
if str <> '' then str := str + ', ';
flightInfoDataModule.passengerManifestQuery.RecNo := index + 1;
vari :=
flightInfoDataModule.passengerManifestQuery['passenger_name'];
str := str + vari;
index := index + 1;
end; // while
subReport.ObjectByName(bandIndex, objectIndex, 'txtPassengers');
subReport.bands[bandindex].objects[objectindex].settext('Passengers:
' + str);
//Application.MessageBox(pchar(str),'fuck',MB_OK);
end; //end if
reportlist.Free;
//subreport.Free;
end;
chooses a report to print ill pull the report out and dynamically assign a
function the the report's subreport beforeprint event. In this event i
dynamically set lablels and memo fields text. This event is fired 90% and
everything works really well. but every once in a while the event does not
seem to fire and the user has to shut down my delphi app and restart for the
printing to work correctly again. I can not reproduce the error on my
development machine while trying to debug the problem - it only happens on
the users machines and randomly so its very hard to pin down. here is a
large block of code showing how i pull the report out of the DB and assign
the function to the subreports beforePrint event. Hopefully this makes sense
and any help is greatly appreciated
-- Matt
its a ton of code i know but im hurting here - the first function is what is
fired when the users chooses to print - the second function is the
beforePrint fucntion that is assigned to the before print event for the sub
report
procedure TflightWorksheetForm.CharterQuote1Click(Sender: TObject);
var
lPrintDevice: tppprinterdevice;
bandIndex : integer;
objectIndex : integer;
temp : variant;
wasFiltered : boolean;
reportList : TStringList;
subReport : TppChildReport;
bandIndex : integer;
objectIndex : integer;
begin
screen.cursor := crHourglass;
if not flightInfoDataModule.flightLegQuery.filtered then begin
wasFiltered := false;
btnHideCancelledClick(Self);
end
else
wasFiltered := true;
OpenDBObjects;
//create the report object
flightReport := TflightReport.Create(Self);
reportBuilderDataModule.reportTemplateTable.close;
reportBuilderDataModule.reportTemplateTable.open;
flightReport.Template.DatabaseSettings.DataPipeline :=
reportTemplatesPipeline;
flightReport.template.DatabaseSettings.NameField := 'report_name';
flightReport.template.DatabaseSettings.TemplateField :=
'report_template';
flightReport.template.DatabaseSettings.Name := 'charterQuote';
flightReport.template.LoadFromDatabase;
carrierItinerary := false;
printManifest := false;
//set the flight leg band before print
reportList := tstringlist.Create();
flightReport.GetSubReports(reportList);
subReport :=
TppChildReport(reportList.objects[reportList.indexof('flightLegReport:
flightLegPipeline')]);
subreport.ObjectByName(bandIndex, objectIndex, 'lblTime');
subreport.bands[bandIndex].BeforePrint := flightLegBandBeforePrint;
reportlist.free;
//set the footer before print
flightReport.ObjectByName(bandIndex,objectIndex,'lblSignature');
flightreport.Bands[bandIndex].BeforePrint := footerBandBeforePrint;
//set the report before print and after print
flightReport.BeforePrint := flightReportBeforePrint;
SetAddressIndexes;
//set the quote fields
flightReport.ObjectByName(bandindex, objectindex, 'lblQuote');
if trim(txtQuickQuote.text) = '' then
temp := ''
else
temp:= '$' + FormatFloat('#,##0.00',strtofloat(txtQuickQuote.text));
flightReport.Bands[bandindex].objects[objectindex].settext(temp);
flightReport.ObjectByName(bandindex, objectindex, 'lblTax');
flightReport.Bands[bandindex].objects[objectindex].settext('+ ' +
floattostr(globalTax * 100) + '% Federal Excise Tax');
useTailNumber := false;
/////set the printer and print///////////////////
lPrintDevice := tppprinterdevice.Create(Self);
lPrintDevice.Publisher := flightReport.Publisher;
flightReport.PrintToDevices;
lPrintDevice.Free;
//flightReport.print;
//////////////////////////////////
flightReport.Free;
if not wasFiltered then btnShowCancelledClick(Self);
screen.cursor := crArrow;
end;
procedure TflightWorksheetForm.flightLegBandBeforePrint(Sender: TObject);
var
tailNumber : variant;
temp : variant;
tempString : string;
timeString : string;
position : integer;
tempTail : string;
bandIndex : integer;
objectIndex : integer;
subReport : TppChildReport;
reportList : TStringList;
index : integer;
str : string;
vari : variant;
flilegId : variant;
dataSet : TADOQuery;
begin
reportList := tstringlist.Create();
flightReport.GetSubReports(reportList);
if carrierItinerary then begin
subReport :=
TppChildReport(reportList.objects[reportList.indexof('flightLegReport:
flightLegsForCarrierPipeline')]);
dataSet := flightInfoDataModule.flightLegsForCarrierQuery;
end
else begin
subReport :=
TppChildReport(reportList.objects[reportList.indexof('flightLegReport:
flightLegPipeline')]);
dataSet := flightInfoDataModule.flightLegQuery;
end;
tailNumber := dataSet['tail_number'];
//get the indexes for lblDepart
subReport.ObjectByName(bandIndex, objectIndex, 'lblDepart');
if useTailNumber then begin
if tailNumber = Null then begin
temp := dataSet['departString'];
tempString := temp;
subReport.bands[bandindex].objects[objectindex].SetText(pchar(tempString + '
TBA'));
tempTail := 'TBA';
end
else begin
tempTail := tailNumber;
temp := dataSet['departString'];
tempString := temp;
subReport.bands[bandindex].objects[objectindex].SetText(pchar(tempString));
end;
end
else begin
temp := dataSet['departQuoteString'];
tempString := temp;
subReport.bands[bandindex].objects[objectindex].SetText(pchar(tempString));
end;
//print out the start time
temp := dataSet['flileg_start_time'];
//get the indexes for lblTime
subReport.ObjectByName(bandIndex, objectIndex, 'lblTime');
if temp <> Null then begin
timeString := temp;
position := AnsiPos(':', timeString);
timeString := copy(timestring, (position-2), 7);
subReport.bands[bandindex].objects[objectindex].settext(timeString);
end
else
subReport.bands[bandindex].objects[objectindex].settext('');
//print out the end time
temp := dataSet['flileg_end_time'];
//get the indexes for lblEndTime
subReport.ObjectByName(bandIndex, objectIndex, 'lblEndTime');
if temp <> Null then begin
timeString := temp;
position := AnsiPos(':', timeString);
timeString := copy(timestring, (position-2), 7);
subReport.bands[bandindex].objects[objectindex].settext(timeString);
end
else
subReport.bands[bandindex].objects[objectindex].settext('');
//figure out if there are multiple tail numbers
//get the indexes for lblTailNumber
if useTailNumber then begin
flightreport.ObjectByName(bandIndex, objectIndex, 'lblTailNumber');
if flightLegCount = 0 then begin
tailNumber := tempTail;
flightreport.bands[bandindex].objects[objectindex].settext(tailNumber);
flightLegCount := 1;
end
else begin
if tailNumber = Null then tailNumber := '';
if trim(tempTail) <> trim(tailNumber) then
flightreport.bands[bandindex].objects[objectindex].settext('See Below');
end;
end;
if printManifest then begin
flilegId := dataSet['flileg_id'];
flightInfoDataModule.passengerManifestQuery.close;
flightInfoDataModule.passengerManifestQuery.Parameters.items[0].value :=
flilegId;
flightInfoDataModule.passengerManifestQuery.open;
index := 0;
str := '';
while index <
flightInfoDataModule.passengerManifestQuery.RecordCount do
begin
if str <> '' then str := str + ', ';
flightInfoDataModule.passengerManifestQuery.RecNo := index + 1;
vari :=
flightInfoDataModule.passengerManifestQuery['passenger_name'];
str := str + vari;
index := index + 1;
end; // while
subReport.ObjectByName(bandIndex, objectIndex, 'txtPassengers');
subReport.bands[bandindex].objects[objectindex].settext('Passengers:
' + str);
//Application.MessageBox(pchar(str),'fuck',MB_OK);
end; //end if
reportlist.Free;
//subreport.Free;
end;
This discussion has been closed.
Comments
assume. The BeforePrint event doesn't fire for a subreport? When are you
assigning the BeforePrint event handler to the subreport's BeforePrint event
when the report template is loaded into the report component?
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com