Recent

Author Topic: Collate/sorting not working  (Read 5418 times)

jgdumont

  • Newbie
  • Posts: 6
Collate/sorting not working
« on: May 22, 2014, 04:01:03 pm »
Hi,

I'm having some problems with printing my report.
I've been able to create a rather nice report (I'm proud if). When the report is shown in preview mode it looks fine and printing one report is no problem. I just wonder wy there are used 2 print dialogs. I mean, when you just hit "OK" then te report is printed immediately.  But when you click "proportions" There is another similar looking dialog with a bit more options. It really goes wrong when i want more then one copy and want it to be sorted. No matter I select "sorted" ore not the output to the printer is NOT sorted. Fore example: I wont 3 copy's from a 2 page report, i get the order 1,1,1,2,2,2,3,3,3 instead of 1,2,3,1,2,3,1,2,3. I already tried to bypass the first dialog by not creating a preview but printed the report from code:
Code: [Select]
procedure TDataModule_Rapporten.print;
var
  FromPage, ToPage, NumberCopies: Integer;
  ind: Integer;
  AppDirectory: String;
  Collap: Boolean;
begin
  // Load report definition from application directory
  frReportPlanning.LoadFromFile('rapporten\Planning.lrf');
  // Need to keep track of which printer was originally selected to check for user changes
  ind:= Printer.PrinterIndex;
  // Prepare the report and just stop if we hit an error as continuing makes no sense
  if not frReportPlanning.PrepareReport then Exit;
  // Set up dialog with some sensible defaults which user can change
  with PrintDialog1 do
  begin
    Options:=[poPageNums]; // allows selecting pages/page numbers
    Copies:=1;
    Collate:=true; // ordened copies

    FromPage:=1; // start page
    ToPage:=frReportPlanning.EMFPages.Count; // last page
    MaxPage:=frReportPlanning.EMFPages.Count; // maximum allowed number of pages
    if Execute then // show dialog; if succesful, process user feedback
    begin
      if (Printer.PrinterIndex <> ind ) // verify if selected printer has changed
        or frReportPlanning.CanRebuild // ... only makes sense if we can reformat the report
        or frReportPlanning.ChangePrinter(ind, Printer.PrinterIndex) //... then change printer
        then
        frReportPlanning.PrepareReport //... and reformat for new printer
      else
        exit; // we couldn't honour the printer change

      if PrintDialog1.PrintRange = prPageNums then // user made page range selection
      begin
        FromPage:=PrintDialog1.FromPage; // first page
        ToPage:=PrintDialog1.ToPage;  // last page
      end;
      NumberCopies:=PrintDialog1.Copies; // number of copies
      collate:=PrintDialog1.Collate;
      // Print the report using the supplied pages & copies
      showmessage('test');
      frReportPlanning.PrintPreparedReport(inttostr(FromPage)+'-'+inttostr(ToPage), NumberCopies);
    end;
  end;
end;               

But without any difference in the printer output.

(This code I copied from http://wiki.lazarus.freepascal.org/LazReport_Tutorial#Printing )

When my compiled program is running on windows server 2003 the problem is the same.
Printing and collating from other applications is no problem.

I'm Using Windows 7 as OS and my lazarus version is 1.2.2 (SVN 44758)

Any help would be appreciated.

jgdumont

  • Newbie
  • Posts: 6
Re: Collate/sorting not working
« Reply #1 on: June 02, 2014, 01:29:08 pm »
Nobody??...

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Collate/sorting not working
« Reply #2 on: June 02, 2014, 01:30:42 pm »
Well, it always help if you attach the source code (no .ppu, no executables) of a compilable sample application as a zip to your post. That way others can more quickly try to help.

See first link in my signature.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Collate/sorting not working
« Reply #3 on: June 02, 2014, 01:36:10 pm »
My advice, remove the with statement and your problem will probably go away.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jgdumont

  • Newbie
  • Posts: 6
Re: Collate/sorting not working
« Reply #4 on: June 10, 2014, 10:21:12 pm »
Thanks for your reactions so far.

It did not make any difference without the with statement. Because my project is quit big and the start is depending on an log in on a mysql database i'm not able to send the original project. But I've been able to reproduce some strange behavior that (in my opinion) causes the problem.
This is what I did:
  • Created an new project (aplication)
  • Added a button, a printdialog and a report.
  • designd a verry simmple report (without anny bands, just a green ractangle with a page number variable)

When the button is pressed the following procedure is called:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);

var
  FromPage, ToPage, NumberCopies: Integer;
  ind: Integer;
begin
  // Load report definition from application directory
  frReport1.LoadFromFile(GetcurrentDir()+'\test.lrf');
  // Need to keep track of which printer was originally selected to check for user changes
  ind:= Printer.PrinterIndex;
  // Prepare the report and just stop if we hit an error as continuing makes no sense
  if not frReport1.PrepareReport then Exit;
  // Set up dialog with some sensible defaults which user can change

    PrintDialog1.Options:=[poPageNums]; // allows selecting pages/page numbers
    PrintDialog1.Copies:=1;
    PrintDialog1.Collate:=true; // ordened copies

    FromPage:=1; // start page
    PrintDialog1.ToPage:=frReport1.EMFPages.Count; // last page
    PrintDialog1.MaxPage:=frReport1.EMFPages.Count; // maximum allowed number of pages
    if PrintDialog1.Execute then // show dialog; if succesful, process user feedback
    begin
      if (Printer.PrinterIndex <> ind ) // verify if selected printer has changed
        or frReport1.CanRebuild // ... only makes sense if we can reformat the report
        or frReport1.ChangePrinter(ind, Printer.PrinterIndex) //... then change printer
        then
        frReport1.PrepareReport //... and reformat for new printer
      else
        exit; // we couldn't honour the printer change

      if PrintDialog1.PrintRange = prPageNums then // user made page range selection
      begin
        FromPage:=PrintDialog1.FromPage; // first page
        ToPage:=PrintDialog1.ToPage;  // last page
      end;
      NumberCopies:=PrintDialog1.Copies; // number of copies
      FromPage:=PrintDialog1.FromPage; // first page
      ToPage:=PrintDialog1.ToPage;  // last page
      // Print the report using the supplied pages & copies
      showmessage(IntToStr(NumberCopies)+' maal afdrukken van pagina '+IntToStr(Frompage) +' tot '+IntToStr(Topage));
      frReport1.PrintPreparedReport(inttostr(FromPage)+'-'+inttostr(ToPage), NumberCopies);
    end;
end;

This is what happens with the compiled program:

The printdialog is shown. When i just select the "ok" button, there is 1 page printed.
But when I select to print 2 copies and unchecked collate, actually 4 copies are printed.
When I select to print 2 copies and leave the collate check-box checked, I get only 1 print-out.
When I select to print 3 copies and leave the collate check-box checked, 9 copies are printed.
The affect of checking or unchecking the collate check-box seems randomly.

A copy of the project is attached.

Thanks fore any help.


 

TinyPortal © 2005-2018