Home End User

No effect on aCancel=true

edited June 2011 in End User
Hi!

In the code below in the event OnIntializeParameters the aCancel=true has no
effect. The message MyMsg is displayed as it should, and then the
AutoSearchDialog is displayed. According to help "Set the Cancel parameter
to True to cancel the report generation process". What i want to achieve is
to abort any report that don't have the parameter "provider". The report is
selected in a end-user reportexplorer. What is the problem?

Best regards,
Terje



procedure TfrmRapporter.rptMainInitializeParameters(Sender: TObject; var
aCancel: Boolean);
var
lParams: TStrings;
begin
lParams := TStringList.Create;
try
rptMain.Parameters.GetNames(lParams);
if (lParams.Count > 0) then
begin
if (lParams.IndexOf('provider') <> -1) then
rptMain.Parameters['provider'].Value := AProvider
else
begin
MyMsg(ftError,'Finner ikke parameter for provider. Rapport blir ikke
kjørt.','Feil',12);
aCancel := true;
end;
end else
begin
MyMsg(ftError,'Finner ikke parameter for provider. Rapport blir ikke
kjørt.','Feil',12);
aCancel := true;
end;
finally
lParams.Free;
end;
end;

Comments

  • edited June 2011

    Try tracing the code in ppReport.pas for the method TppReport.Print. Here
    is what the code looks like...

    procedure TppReport.Print;
    begin

    if not InitializeParameters then Exit;

    if (ShowAutoSearchDialogBeforePrinting) then
    inherited Print;

    end;


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2011
    The function InitializeParameters always returns TRUE.

    I belive it is this line " lParams.CreateValuePointer(0, lbCancel); " that
    does it.

    What can i do to solve this problem? Would it cause any problem if i comment
    out this line?

    Regards, Terje


  • edited June 2011

    I tried a simple test here and did not encounter any issues. I created a
    report with DBDemos data. I created a query on the customer data that
    contains an autosearch condition. I implemented the OnInitializeParamters
    event like this...

    procedure TForm2.ppReport1InitializeParameters(Sender: TObject; var aCancel:
    Boolean);
    begin
    aCancel := True;
    end;

    I call Report.Print like this...

    procedure TForm2.Button1Click(Sender: TObject);
    begin
    ppReport1.Print;
    end;

    I build and run the project. when the button is clicked, no auto-search
    dialog is displayed, no report is generated.


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2011
    As i wrote in my first mail the report is run from within a ReportExplorer.
    I never do any ppReport1.Print. What method is called when a report is run
    from within the explorer i don't know. I have written the value of lbCancel
    and Result of InitializeParameters to a file while executing a report. The
    lbCancel is correct but the InitializeParameters always returns TRUE.

    Terje



  • edited June 2011

    My thinking was to try the simplest test to determine whether the event
    works correctly.

    I just now performed the same test in the ReportExplorer and did not
    encounter any issues. I implemented the OnInitializeParamters event in RAP
    code.

    procedure ReportOnInitializeParameters(Sender: TObject; var aCancel:
    Boolean);
    begin

    aCancel := True;

    end;

    The ReportExplorer also calls Print. See ppRptExp.pas, the methods
    TppReportExplorer.Print and TppReportExplorer.PrintPreview.



    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2011
    I know you are trying to help the best you can and i'm greatful for that.
    And maybe my description of the problem is bad. But it is a fact that in my
    case the method InitializeParameters always returns true, and as far as i
    can see in the source, it should return false for the printing to be
    cancelled.

    I have implemented the OnInitializeParameters event in the delphi end-user
    application. The event works correctly and the var aCancel has the value i
    set in the event. Below is my attempt to show what happens.

    PART OF SOURCECODE FROM InitializeParameters
    if Assigned(FOnInitializeParameters) then FOnInitializeParameters(Self,
    lbCancel);
    sendbol('lbCancel',lbCancel); // 1
    lParams := TraTppReportRTTI.GetParams('OnInitializeParameters');
    lParams.CreateValuePointer(0, lbCancel);
    sendbol('lbCancel',lbCancel); // 2
    SendEventNotify(Self, ciReportInitializeParameters, lParams);
    lParams.Free;
    sendbol('lbCancel',lbCancel); // 3
    Result := not lbCancel;
    sendbol('Result',Result); // 4


    Here is the result of my debug in the event.

    29.06.2011 13:39:33 : ----- DEBUG : BDStartDLL.exe ---------- //
    aCancel=false
    29.06.2011 13:39:35 : lbCancel = False // 1
    29.06.2011 13:39:35 : lbCancel = False // 2
    29.06.2011 13:39:35 : lbCancel = False // 3
    29.06.2011 13:39:35 : Result = True // 4
    29.06.2011 13:40:56 : ----- DEBUG : BDStartDLL.exe ---------- //
    aCancel=true
    29.06.2011 13:40:58 : lbCancel = True // 1
    29.06.2011 13:40:58 : lbCancel = True // 2
    29.06.2011 13:40:58 : lbCancel = False // 3 HOW CAN THIS BE
    FALSE?
    29.06.2011 13:40:58 : Result = True // 4

    Can you explain what is happening here? I can't.



    Regards,
    Terje




  • edited June 2011
    In your initial post for this thread, you show a Delphi code event-handler.
    Later you say you are using RAP code and ReportExplorer.

    I have created two different test cases here, one for Delphi code and one
    for RAP code. The one for RAP code I created and saved via the
    Demos\EndUser\ReportExplorer.

    The test cases produce the correct result.

    I traced the test cases in the Delphi debugger and the code produces the
    correct result at each step of the TppReport.InitializeParameters method.

    I recommend that you put your 'real code' aside for a moment. Create the
    same test cases that I have done here and try those out.

    Your debug output shows the Report.InitializeParameters code is firing two
    times. It should fire a single time. In my testing here InitializeParameters
    fires a single time.


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited July 2011
    This is a multi-part message in MIME format.
This discussion has been closed.