DrawQR
Download Latest Version Index History Template Class
CapeSoft Logo

CapeSoft DrawQR
Documentation

Installed Version Latest Version

Introduction

The DrawQRClass class is based on the DrawClass class. It allows QR codes to be generated from text. These QR codes can be used on the screen, on a report, or saved to a file (BMP or PNG).

QRCodeGen Library

The underlying engine is the C implementation of Project Nayuki, implemented in QRCodeGen.DLL. It is used under the terms of the MIT License.

JumpStart

  1. Make sure the Draw Global Extension is added to the application.
  2. Go to a window, populate the DrawQR control onto it.
  3. Fill in the template options.
  4. If the QR Code is not known when the window opens (ie you left Initial value blank)
    OR if you want to change the QR code at some point when the window is open, call

    ThisQR1.GenerateImage('whatever value you like')

Template

Draw provides a control template, which allows you to quickly and easily add a QR Code to your window or report without needing to write any code, or call any of the methods directly.

Global Extension

Before you can use the DrawQR template on a window you will need to add the Draw Global Extension to the application. To do this go to the Global Extensions section of your application, click on Insert and select the Draw global extension. All of the settings can be left at their default values at this point, with the exception of the Multi-DLL tab (if you are working in a multi-app program.)

If you are working in a program that consists of multiple app files, then you will need to set the settings on the Mutli-DLL tab correctly in your Data DLL, other DLL's and EXE's. See https://www.capesoft.com/accessories/standards.htm#MultiDLLApplications for more information.

Once the global extension template has been added then you are ready to add QR Codes to your application.

Control Template

To add a QR control on a window or report;
  1. Go to the Window Designer or Report Designer
  2. Go to the Control Templates Pad.
  3. Click on the DrawQR item in the Draw section
  4. Click on the window/report where you want the QRcontrol to be.
  5. Once added the control can be positioned and sized as desired.
  6. Right-Click on the control and select Actions to see the template settings for the control.

General Tab

Value
If the QR Code value is known when the window opens, then you can enter it here. Use quotes for a fixed value, or enter some variable name, or expression.
On Browses and reports this value can also be used for NewSelection on the browse, or for every detail on the report.
Auto Display
If this is on then the control will automatically be updatd whenever CreateImage is called. This defaults to on.
Auto Resize
If set on, the control on the template will resize to draw the QR-Code in full-size. If off then the control size is fixed, and the normal setting for the image control (Centered, Stretched) will determine how the QR Code is displayed. This defaults to off.
Error Correction
Set to one of the options. See Properties for more information on these values.
Mode
Set to one of the options. See Properties for more information on these values.
Pixel Size
The size of each "square" in the QR code, in pixels. Defaults to 5.
Border Size
Specifies the border (in pixels) around the QR code. Defaults to 5.
Do not generate this object
This disables the template in this window and no template code for the control will be generated. (the control itself will remain on the screen.) This setting is useful for debugging.

Browse Tab

Regenerate image on Browse New Selection
If this is on then the image is regenerated whenever a NewSelection event is triggered on the browse. In effect this makes the QR Code image a "hot field" of the browse. Like other hot fields, the Image field should be added to the View. (In other words, if the QR Code is say on cus:website, then cus:website must be in the Browse View. You can add fields to the view via the Hot Fields settings on the Browse Control Template.)
Browse Name
If the app is an ABC app, then enter the Object Name for the associated browse to watch here.

If the app is a legacy app, then inspect the generated code to see the name that the template is using for this browse. Typically it's something like BRW1 or something like that.

Report Tab

Regenerate image for each record
If this is on then a call to GenerateImage will be made for each record in the report (using the initial value value). this is a good option if the report is simple, and you will be generating a unique QR code for each record. If however your report is more complicated, and only needs to regenerate QR codes before some details, then it may be more efficient to set this option off, and them manually call ThisQR2.GenerateImage(whatever).

Classes Tab

Object name
The name of this QRCode object.
Class name
The class to use for this gauge object. Default is DrawQRClass.

Using QR Codes in a Hand-Coded Project

Using the DrawQRClass class in a hand-coded project is fairly straight-forward.
  1. Add the conditional compile switches to your project
    Equate Description
    DrawLinkMode Set to 1 if this project will compile the classes, or 0 if the classes are exported into this project via a LIB file.
    DrawDLLMode Typically the inverse of the setting above. Set to 1 is the class is in another DLL, 0 if local to this project.
    DrawImage Set to 1 if the object will make use of the WritePNG method (or any other method that requires FreeImage)
  2. Add the DOS and TOPSPEED file drivers to your project.
  3. Add an INCLUDE to your project

    INCLUDE('DRAWQR.INC'),ONCE
  4. Declare your object

    QR   DrawQRClass
  5. Initialize the object

    QR.Init(?someImageControl)
  6. Set Properties

    QR.Border = 10
  7. Generate the image

    QR.GenerateImage('Some Text')

DrawQRClass Reference

The DrawQR class is derived from the Draw class, and all the methods and properties in that class are in scope here.

Method Reference

DrawGuage Methods
GenerateImage Sets a Draw object to a QR Code image.
GenerateIntoImage Injects a QR Image into a Draw object, at a specific position.
GenerateText Generates a Text form of a QR Code. In other words the result of this is a String, not an image.


GetSize Returns the size of the QR Code for a specific set of text.
Init Called to initialize the object to the Image control on the window.
Start Called before you start using the object. This restores the object to "clean" initial settings, especially useful if you are reusing the object to display a completely QRCode.


Useful Inherited Methods
ToClipboard Copy the contents of the image to the clipboard. Suitable for then pasting in Word, or Paint, or wherever images can be pasted.
WriteBMP
Save the image to the disk as a BMP file.
WritePNG Save the image to the disk as a PNG file.


DrawQRClass

GenerateImage

GenerateImage(String pText)

Description

Takes in some text, and converts it into a QRCode image. If the AutoDisplay property is 0 then the image is drawn into the Draw object, but not to the screen. Use the DISPLAY method when you want to update the screen with the image.

Parameters
Parameter Description
pText The text to encode.
Returns

Nothing

Examples

ThisQR DrawQRClass
code
ThisQR.Start()
ThisQR.Init(?SomeImage)
ThisQR.GenerateImage('some text goes here')

or

ThisQR  DrawQRClass
  code
  ThisQR.Start()
  ThisQR.Init(?SomeImage)
  ThisQR.ECC = R_Ecc_HIGH                    
! set some properties
  ThisQR.GenerateImage('some text goes here')
  ThisQR.WriteBMP('c:\temp\a.bmp')           
! save as a file
 
or

ThisQR DrawQRClass
  code
  ThisQR.Start()
  ThisQR.Init(?SomeImage)
  ThisQR.ECC = QR_Ecc_HIGH
  ThisQR.AutoDisplay = false
                  ! turn off auto display
  ThisQR.GenerateImage('some text goes here')
    ! ... other things here
  ThisQR.WriteBMP('c:\temp\a.bmp') 
  ThisQR.Display()                           
! manually call Display when desired

See Also


GenerateText

DrawQRClass

GenerateIntoImage

GenerateIntoImage(String pText, Long pXPos, Long pYPos)

Description

Takes in some text, and converts it into a QRCode image. The image is drawn into a draw object, but not to the screen. Use the DISPLAY method when you want to update the screen with the image. The object is not blanked, or resized. The other contents in the object are untouched.

Parameters
Parameter Description
pText The text to encode.
pXpos The x position to place the QR code.
pYpos The y position to place the QR code.
Returns

Nothing

Examples

ThisQR DrawQRClass
code
ThisQR.Start()
ThisQR.Init(?SomeImage)
ThisQR.ECC =
QR_Ecc_HIGH
ThisQR.GenerateIntoImage('some text goes here',50,50)
ThisQR.WriteBMP('c:\temp\a.bmp')
ThisQR.Display()

See Also


GenerateText

DrawQRClass

GenerateText

GenerateText(String pText)

Description

Takes in some text, and converts it into a QRCode string. The string is a CR/LF separated set of lines, where one character (space) represents a white square, and one character (X by default) represents a black square. It can be displayed in a TEXT control (with the HVSCROLL attribute and a fixed-width-font) however it is unlikely a scanner will be able to scan this text.

Parameters
Parameter Description
pText The text to encode.
Returns

A string containing a text form of the QR code.

Examples


ThisQR  DrawQRClass
  code
  ThisQR.Start()
  somestring = ThisQR.GenerateText('some text goes here')
 

See Also


GenerateImage

DrawQRClass

GetSize

GetSize(String pText)

Description

Determines the size of the QR Code image in pixels. The size ("version") of the QR code, and the number of pixels per square are taken into account.

Parameters
Parameter Description
pText The text to encode.
Returns

A long containing the size of the QR Code image (in pixels). In other words, self.pix * self.size .

Examples

ThisQR.Init(?SomeImage)

See Also


GenerateImage

DrawQRClass

Init

Init(LONG Control, <Report pReport>)

Description

Initializes the object to an image control on the window.

Parameters
Parameter Description
Control The use equate of an image control on the window.
pReport If the QR Code is on a report, then put the report structure in here. If you do this then you don't need to call SetTarget before calling GenerateImage.
Returns

Nothing

Examples

ThisQR.Init(?SomeImage)

See Also


GenerateImage

DrawQRClass

Start

Start()

Description

Returns the object back to the point as if it has just been created. This allows a single object to be reused, without there being side-effects from previous uses of the object.

Returns

Nothing

Remarks



Examples

self.start()

DrawQRClass

Properties

Properties
AutoDisplay Byte Set to true if the image should automatically call DISPLAY when being generated. Default is true. If set to false a manual call to ThisQR.Display() will be needed to transfr the image to the screen.
AutoResize Byte If this is set to true then the control on the window will be resized to fit the image, at the specified pix per box. If set to false then the image is centered, or stretched (or tiled) depending on the Image control properties.
BackgroundColor Long The QRCode will be cleared to this color before drawing. (This basically means this becomes the border color.)
Border Byte The size of the border around the QR Code. This defaults to 0.
Char String(1) When creating Text QR Codes, this is the character used for the "black" square. Defaults to 'X'.
Color1 Long The colors used in the QR Code itself. Default values are Black and White.
Color2 Long
Ecc Byte The Error Correction value to include in the QR Code. Higher values result in bigger QR Codes, but are more tolerant of scanning errors. The default value is QR_Ecc_QUARTILE. The possible options are;
QR_Ecc_LOW      Equate(0)  ! The QR Code can tolerate about  7% erroneous codewords
QR_Ecc_MEDIUM   Equate(1)  ! The QR Code can tolerate about 15% erroneous codewords
QR_Ecc_QUARTILE Equate(2) ! The QR Code can tolerate about 25% erroneous codewords
QR_Ecc_HIGH     Equate(3) ! The QR Code can tolerate about 30% erroneous codewords
Max Byte The maximum size of the QR Code. (This is known as "version" in the QR world, but is not like a code "version".) The engine supports a size up to 40, which is in accordance with the QR Specification. Defaults to 40.
Min Byte The minimum size of the QR Code. The engine supports a size down to 1, which is in accordance with the QR Specification. Defaults to 1. The actual size of the resultant QR code depends on the amount of information in the text.
Mode Long QR Codes can be generated in different modes. This has an impact on the size of the image. For example knowing that a code contains only numbers allows the QR code to be smaller. The possible options are;
QR_Mode_AUTO         Equate(-1)
QR_Mode_NUMERIC      Equate(1)
QR_Mode_ALPHANUMERIC Equate(2)
QR_Mode_BYTE         Equate(4)
The default is QR_Mode_AUTO
Pix Byte The number of pixels per 'square' in the resultant QR Code. The default value is 5.
Size Byte The size of the QR code, as generated by the engine. You can inspect this property after generating the QR Code to determine the size of the code. This is the size in "boxes" (also known as the QR Version) - so to get the pixel size multiple by pix, and add the border twice.