PrintToDevices and OnGetAutoSearchValues
Hello,
I'm using PrintToDevices to generate report to an archive.
PrintToDevices doesn't call the OnGetAutoSearchValues event.
It only works, when I call DisplayAutoSearchDialog before PrintToDevices.
Have a look at my code at the end of this message.
Any ideas?
Thank you!
Lars Hirthe
CODE:
--------
...
var
BlobStream : TStream;
ArchiveDevice : TppArchiveDevice;
begin
...
ppReport.DeviceType:=dtArchive;
ArchiveDevice:=TppArchiveDevice.Create(nil);
with qryReportArchive do
try
ppReport.OnGetAutoSearchValues:=GetAutoSearchValuesFromParams;
Params[0].AsInteger:=AIDreportarchive;
Open;
if AIDreportArchive>0 then
Edit
else
Insert;
BlobStream:=CreateBlobStream(FieldByName('Data'),bmWrite);
BlobStream.Seek(0,soFromBeginning);
ArchiveDevice.OutputStream:=BlobStream;
ArchiveDevice.Publisher:=ppReport.Publisher;
// ------------------------------
ppReport.SendEventNotify(ppReport,
ciReportBeforeAutoSearchDialogCreate, NIL);
ppReport.SendEventNotify(ppReport, ciReportGetAutoSearchValues, NIL);
// ------------------------------
ppReport.PrintToDevices;
BlobStream.Free;
Post;
AIDReportArchive:=FieldByName('ID').AsInteger;
finally
Close;
ArchiveDevice.Free;
ppReport.OnGetAutoSearchValues:=nil;
end;
end;
I'm using PrintToDevices to generate report to an archive.
PrintToDevices doesn't call the OnGetAutoSearchValues event.
It only works, when I call DisplayAutoSearchDialog before PrintToDevices.
Have a look at my code at the end of this message.
Any ideas?
Thank you!
Lars Hirthe
CODE:
--------
...
var
BlobStream : TStream;
ArchiveDevice : TppArchiveDevice;
begin
...
ppReport.DeviceType:=dtArchive;
ArchiveDevice:=TppArchiveDevice.Create(nil);
with qryReportArchive do
try
ppReport.OnGetAutoSearchValues:=GetAutoSearchValuesFromParams;
Params[0].AsInteger:=AIDreportarchive;
Open;
if AIDreportArchive>0 then
Edit
else
Insert;
BlobStream:=CreateBlobStream(FieldByName('Data'),bmWrite);
BlobStream.Seek(0,soFromBeginning);
ArchiveDevice.OutputStream:=BlobStream;
ArchiveDevice.Publisher:=ppReport.Publisher;
// ------------------------------
ppReport.SendEventNotify(ppReport,
ciReportBeforeAutoSearchDialogCreate, NIL);
ppReport.SendEventNotify(ppReport, ciReportGetAutoSearchValues, NIL);
// ------------------------------
ppReport.PrintToDevices;
BlobStream.Free;
Post;
AIDReportArchive:=FieldByName('ID').AsInteger;
finally
Close;
ArchiveDevice.Free;
ppReport.OnGetAutoSearchValues:=nil;
end;
end;
This discussion has been closed.
Comments
The intent of PrintToDevices is simply generate the report pages to
connected devices (Viewer, Archive, Printer, etc). The developer has total
control over which dialogs you want to show etc. The Print method will
initialize the parameters and show the dialog(s) automatically.
If Report.Initializeparameters and Report.DisplayAutoSearchDialog then
Report.PrintToDevices;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I understand it.
But the problem is, that I don't want to show the AutoSearchDialog.
But I have to do it, otherwise, the PrintToDevices doesn't call the
OnGetAutoSearchValues event.
So, how can I use PrintToDevices and OnGetAutoSearchValues without showing
this dialog?
Lars Hirthe
Is there a reason you are calling PrintToDevices rather than Print? Calling
Report.Print with the ShowAutoSearchDialog property set to False will fire
the OnGetAutoSearchValues event and keep the dialog from showing.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
yes, I want to print to an archive (blobfield).
Lars Hirthe
What exactly are you trying to accomplish inside the OnGetAutoSearchValues
event? Would it be possible to move this code to another event? From
looking at our source, this event is not meant to be fired manually unless
new autosearch values are introduced.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I use the AutoSearch feature to set parameters for my SQL statement in the
report,
because parameterized queries are not supported in Report Builder.
Here is one of my OnGetAutoSearchValues method:
procedure TdmReports.GetAutoSearchValuesFromParams(Sender:TObject);
var
I : integer;
begin
with TppReport(Sender) do
begin
For I:=Low(Params) to High(Params) do
AutoSearchFields[I].SearchExpression:=Params[I];
end;
end;
So I need this event in PrintToDevices.
Or do you have another solution?
Lars Hirthe