How to write page of page on Clarion Reports

reports
Tags: #<Tag:0x00007f46d92afae0>

#1

A frequent request is how to add page of page number to Clarion reports.
The issue is when any given page of a report is generated the report engine does not know how many page the total report will contain.

This is code from the TinTools report previewer. This was a free ware tool available in the late 90s/early 2000s.
Since it was a free-ware tool that is no longer downloadable I think it is OK to publish it on ClarionHub.

The key is to add a control to your report with the literal text page xxxxx of xxxxx. This code searches the generated meta files after the report completes looking for that text and replacing it with the correct values for that page.
This code needs to be called after the report has completed. The ReportManager EndReport method after the parent call is a good place.
This method is modified from the original to work as a method of the ReportManager class instead of the TinTools previewer.

ReportManager.CheckForPageNum PROCEDURE

PAGENUMOFWRK       STRING(19)
PREV:MetaFileName  STRING(100),Static
PREV:Metafile      FILE,DRIVER('dos'),NAME(PREV:MetaFileName)
Record              RECORD,PRE()
MetaLine             STRING(256)
                    END
                   END
ImageCount         Short

 CODE
  ImageCount = RECORDS(SELF.PreviewQueue)
  LOOP TKCounter1# = 1 to ImageCount
    GET(SELF.PreviewQueue, TKCounter1#)
    PREV:MetaFileName = SELF.PreviewQueue
    OPEN(PREV:MetaFile)
    IF ERRORCODE(); CYCLE.
    TKMetaPointer# = 0
    LOOP
      SET(PREV:MetaFile, TKMetaPointer#)
      NEXT(PREV:MetaFile)
      TKCounter2# = instring('Page xxxxx of xxxxx', MetaLine, 1, 1)
      IF TKCounter2# > 0
        PAGENUMOFWRK = 'Page ' & FORMAT(TKCounter1#,@s5)
        PAGENUMOFWRK = CLIP(PAGENUMOFWRK) & ' of ' & FORMAT(ImageCount,@s5)
        PAGENUMOFWRK = CENTER(CLIP(PAGENUMOFWRK),19)
        MetaLine = SUB(MetaLine,1,TKCounter2#-1)|
                     & PAGENUMOFWRK |
                     & SUB(MetaLine,TKCounter2#+19,LEN(MetaLine))
        PUT(PREV:MetaFile)
        BREAK
      END
      IF ERRORCODE() OR EOF(PREV:MetaFile); BREAK.
      TKMetaPointer# = POINTER(PREV:MetaFile) + 236
    END
    CLOSE(PREV:MetaFile)
  END

I can’t take any credit for this (I’d most likely write it a bit differently :slight_smile: ), but it does work.

Enjoy,
Rick


How to use the GetTotalPages() on report
#2

For use With Clarion 10 ABC Report:

  1. Derivate the Previewer Class and add the new method CheckForPageNum, prototype (). Inside the method, change the SELF.PreviewQueue (witch now is a TYPE Definition) for SELF.ImageQueue (3 replaces).
  2. Put the call to this method in ThisWindow.EndReport after Parent Call (Previewer.CheckForPageNum()).
  3. Put a String in your Report Footer exactly like this ‘Page xxxxx of xxxxx’
  4. You can localize it, if needed, by changing the individual 'Page ’ string (by 'Paginas ’ for example) and the ’ of ’ strings later in the code.

Enjoy