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

PrintToDevices and OnGetAutoSearchValues

edited March 2008 in General
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;

Comments

  • edited March 2008
    Hi Lars,

    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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2008
    Hi Nico,

    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

  • edited May 2008
    Hi Lars,

    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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2008
    Hi Nico,

    yes, I want to print to an archive (blobfield).

    Lars Hirthe

  • edited May 2008
    Hi Lars,

    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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2008
    Hi Nico,

    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

This discussion has been closed.