Subject Re: logical field in report
From Mervyn Bick <invalid@invalid.invalid>
Date Fri, 12 Jan 2018 10:14:33 +0200
Newsgroups dbase.getting-started
Attachment(s) test_checkmark.rep

On 2018-01-12 12:02 AM, Charlie wrote:
> Happy New Year!!
>
> Wondering if there is a way of showing a check box with checks for true instead of true or false in the streamsource of a report???  (I'm  looking for an easy way I am missing in the report.)  Thanks much!!!
>


One can use the canRender event handler for a text object to change
anything in a field to virtually anything else before placing it in the
report.

The Unicode character 0x2610 is a box and the Unicode character 0x2611
is a box with a tick.  In other words they look just like a set and an
unset checkbox do on a form.

You can find a list of the Unicode characters at
https://en.wikipedia.org/wiki/List_of_Unicode_characters

Although dBASE normally uses single byte ASCII characters in strings,
behind the scenes dBASE has made provision for two bytes per character.
Normally the high byte is set to 0 for the standard ASCII charcters but
if we want to display two-byte characters setByte() allows us to set the
individual bytes.

The Unicode characters seem to print smaller than the normal characters
so it is necessary to increase the fontsize for the text object.


  function TEXTCHECKMARK2_canRender()
     cText = ' '
     if this.form.test_checkmark1.rowset.fields["checkmark"].value = true
        cText.setByte(1,0x26)
        cText.setByte(0,0x11)
     else
        cText.setByte(1,0x26)
        cText.setByte(0,0x10)
     endif
     this.text = cText  //this overwrites the underlying codeblock
     return true

In the constructor code for a text object on a report the text property
is set to a codeblock.  As the test property has been overwritten it is
necessary to replace the codeblock ready for the next record.


  function TEXTCHECKMARK2_onRender()
     //replace codeblock ready for next record
     this.text =
{||this.form.test_checkmark1.rowset.fields["checkmark"].value}
     return


A little example is attached.

Mervyn.




if file('test_checkmark.dbf')
//   drop table test_checkmark
endif

if not file('test_checkmark.dbf')
   create table test_checkmark  (id autoinc,data character(5),checkmark boolean)
  
   use test_checkmark
   generate 10
   use
  
endif

** END HEADER -- do not remove this line
//
// Generated on 2018/01/12
//
local r
r = new TEST_CHECKMARKREPORT()
r.render()

class TEST_CHECKMARKREPORT of REPORT
   with (this)
      metric = 0        // Chars
      autoSort = false
   endwith

   this.TEST_CHECKMARK1 = new QUERY(this)
   with (this.TEST_CHECKMARK1)
      left = 2.8667
      top = 0.65
      width = 4.0
      height = 1.0
      sql = 'select * from "test_checkmark.DBF"'
      requestLive = false
      active = true
   endwith

   this.PAGETEMPLATE1 = new PAGETEMPLATE(this)
   with (this.PAGETEMPLATE1)
      height = 56.1233
      width = 132.0
      marginTop = 3.6
      marginLeft = 12.0
      marginBottom = 3.6
      marginRight = 12.0
      gridLineWidth = 0
   endwith

   this.PAGETEMPLATE1.STREAMFRAME1 = new STREAMFRAME(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.STREAMFRAME1)
      height = 38.65
      left = 4.0
      top = 2.8
      width = 104.0
      form.STREAMFRAME1 = form.pagetemplate1.streamframe1
   endwith

   with (this.printer)
      duplex = 1        // None
      orientation = 1        // Portrait
      paperSource = 7
      paperSize = 9
      resolution = 3        // Medium
      color = 2        // Color
      trueTypeFonts = 1        // Bitmap
   endwith

   this.STREAMSOURCE1 = new STREAMSOURCE(this)
   with (this.STREAMSOURCE1.detailBand)
      height = 2.0
   endwith

   this.STREAMSOURCE1.detailBand.TITLETEXTID1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TITLETEXTID1)
      canRender = {||this.parent.firstOnFrame}
      height = 1.0
      left = 2.6667
      top = 0.12
      width = 5.5
      prefixEnable = false
      alignHorizontal = 2        // Right
      suppressIfBlank = true
      text = "<H3>Id</H3>"
   endwith

   this.STREAMSOURCE1.detailBand.TEXTID1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTID1)
      height = 0.9767
      left = 0.0
      top = 1.0967
      width = 8.1667
      variableHeight = true
      prefixEnable = false
      alignHorizontal = 2        // Right
      text = {||this.form.test_checkmark1.rowset.fields["id"].value}
   endwith

   this.STREAMSOURCE1.detailBand.TITLETEXTDATA1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TITLETEXTDATA1)
      canRender = {||this.parent.firstOnFrame}
      height = 1.0
      left = 12.1667
      top = 0.12
      width = 7.0
      prefixEnable = false
      suppressIfBlank = true
      text = "<H3>Data</H3>"
   endwith

   this.STREAMSOURCE1.detailBand.TEXTDATA1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTDATA1)
      height = 0.9767
      left = 12.1667
      top = 1.0967
      width = 12.8333
      variableHeight = true
      prefixEnable = false
      text = {||this.form.test_checkmark1.rowset.fields["data"].value}
   endwith

   this.STREAMSOURCE1.detailBand.TITLETEXTCHECKMARK1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TITLETEXTCHECKMARK1)
      canRender = {||this.parent.firstOnFrame}
      height = 1.0
      left = 35.0
      top = 0.12
      width = 15.8333
      prefixEnable = false
      suppressIfBlank = true
      text = "<H3>Checkmark</H3>"
   endwith

   this.STREAMSOURCE1.detailBand.TEXTCHECKMARK1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTCHECKMARK1)
      height = 0.9767
      left = 35.0
      top = 1.0967
      width = 14.3333
      variableHeight = true
      prefixEnable = false
      text = {||this.form.test_checkmark1.rowset.fields["checkmark"].value}
   endwith

   this.STREAMSOURCE1.detailBand.TITLETEXTCHECKMARK3 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TITLETEXTCHECKMARK3)
      canRender = {||this.parent.firstOnFrame}
      height = 1.0
      left = 64.8334
      top = 0.12
      width = 15.8333
      prefixEnable = false
      suppressIfBlank = true
      text = "<H3>Checkmark</H3>"
   endwith

   this.STREAMSOURCE1.detailBand.TEXTCHECKMARK2 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTCHECKMARK2)
      canRender = class::TEXTCHECKMARK2_CANRENDER
      onRender = class::TEXTCHECKMARK2_ONRENDER
      height = 0.9767
      left = 64.8334
      top = 1.0967
      width = 17.6666
      variableHeight = true
      prefixEnable = false
      fontSize = 14.0
      text = {||this.form.test_checkmark1.rowset.fields["checkmark"].value}
   endwith

   with (this.reportGroup.footerBand)
      height = 0.8333
   endwith

   with (this.reportGroup.headerBand)
      height = 0.8333
   endwith

   this.firstPageTemplate = this.form.pagetemplate1
   this.form.pagetemplate1.nextPageTemplate = this.form.pagetemplate1
   this.form.pagetemplate1.streamframe1.streamSource = this.form.streamsource1
   this.form.streamsource1.rowset = this.form.test_checkmark1.rowset


   function TEXTCHECKMARK2_canRender()
      cText = ' '      
      if this.form.test_checkmark1.rowset.fields["checkmark"].value = true
         cText.setByte(1,0x26)
         cText.setByte(0,0x11)
      else
         cText.setByte(1,0x26)
         cText.setByte(0,0x10)
      endif
      this.text = cText
      return true

   function TEXTCHECKMARK2_onRender()
      //replace codeblock ready for next record
      this.text = {||this.form.test_checkmark1.rowset.fields["checkmark"].value}
      return

endclass