terminate report from code

edited 3:24AM in FastReport 4.0
can anybody help me, how can i terminate the report from code (pascalscript) without showing the preview form?
i set Report.Terminated := True but preview form is always show...
thanks

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 3:24AM
    this will depend upon where in code and for what reason you are trying to terminate the report.

    assuming you loaded and called the report in this manner
    frxreport1.loadfromfile('path&filename');
    frxreport1.showreport;// this forms output and displays preview
    the easiest is to include an frxdialog form in the report
    with 2 buttons (run, cancel) and set their modal result properties to suit.
  • edited 3:24AM
    thank you gordon, but it still doesn't solve my problem. i try describe it in detail:

    i want to print labels using "onmanualbuild" event in report. each label has particular count to print, but some of them have set unlimited count (999999). so when the count is unlimited, i want to show dialog form to specify new count for current label to print, or cancel (terminate) whole report by user without showing preview form.

    sample of source code:

    procedure PageOnManualBuild(Sender: TfrxComponent);
    var
    I, Count: Integer;
    begin
    if Engine.FinalPass then
    begin
    MasterData.Dataset.First;
    while not MasterData.Dataset.Eof do
    begin
    Count := IIF(MasterData.DataSet.Value = NULL, 0, MasterData.DataSet.Value);
    if Count = 999999 then
    if UnlimitedFrm.ShowModal <> mrOk then
    Engine.StopReport; //here i want not only stop report, but terminate it without showing preview form...

    for I:= 1 to Count do
    Engine.ShowBand(MasterData);
    MasterData.Dataset.Next;
    end;
    end;
    end;
  • gordkgordk St.Catherines On. Canada.
    edited 3:24AM
    sorry it is not clear to me
    i don't understand why you are insistent upon using the onmanual build
    and a two passreport.
    can you post a sample app in the binaries news group?
  • edited 3:24AM
    hi gord, it doesn't matter if the report is double pass or not.

    i posted a sample source code to binaries news group with topic "for gordk - terminate report from code"...
    please have a look at it.

    thank you in advance
  • gordkgordk St.Catherines On. Canada.
    edited 3:24AM
    Hi mike
    here is what i would change based on what you posted
    add a variable to the report's categorized variables named Cancelled
    DO NOT give it any value.
    change the report code
    begin
    //here i want to terminate whole report job...
    set('Cancelled',true); //add this line
    Report.Terminated := True;

    end;
    change your delphi code
    procedure TForm2.Button1Click(Sender: TObject);
    begin
    frxReport1.PrepareReport;
    if not frxreport1.variables= true then

    frxReport1.ShowPreparedReport;
    end;

    BTW delphi form onshow event is a better place than oncreate to create client data
    i would load report file in button click event and turn off store in dfm.

  • gordkgordk St.Catherines On. Canada.
    edited 3:24AM
    Mike
    don't try it there is a bug
    ill get back to you
  • edited 3:24AM
    thank you for your quick reply,
    i experimented with the code and i didn't figure out why you added a new variable "Canceled". is it possible to use native variable Terminated instead? See following code:

    procedure TForm2.Button1Click(Sender: TObject);
    begin
    frxReport1.PrepareReport;
    if not frxreport1.Terminated then
    frxReport1.ShowPreparedReport;
    end;

    i tried the code above and it really works. where is the bug you mentioned?

    thank you again



  • gordkgordk St.Catherines On. Canada.
    edited 3:24AM
    yes it is, glad you got it
    i think my head was out in deepspace last night.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.