FoxPro Barcode FAQ for ActiveX and COM

In this FoxPro Barcode FAQ and tutorial, IDAutomation outlines integrating the Barcode ActiveX Control into Microsoft Visual FoxPro 6 and later forms and reports. 

Integrating the ActiveX Control with Graphics

  1. To use the ActiveX Control on a form, switch to 'Design Time', select the "ActiveX Control (OleControl)" on the Form Control toolbar,  and click on the form. After the "Insert Object" dialog box opens, select "Insert Control" option. In the list of all installed ActiveX controls, select a control to use that begins with "IDAutomation".
    Insert Linear Bar Code ActiveX control to form
  2. The characteristics can then be modified in the properties window.
  3. To print barcodes on reports or labels, the Barcode ActiveX control should be embedded and prepared in the table field of type General, and then displayed in the report. This will require some programming of code for preparing the Barcode ActiveX control in the General field.
  4. Assuming there is a data table already created, add to the table the field of type General called "CodeGen".
    Adding a field of General type to the Items table
  5. To display it in a report, put the Picture/ActiveX Bound Control, then select the "File" option and specify General Field and name in it ("Items.CodeGen").
    Specify properties for ActiveX control printing
  6. Then, prepare the code that will populate the General Field by the Barcode ActiveX control with appropriate data from the Code Field for each record in the Items table. This code should run before printing. This can be organized in one of the following ways:
    1. Define code in the custom program that calls a report, such as in the VFP barcode example.
    2. Define code in the BeforeOpenTables event of the data environment in the report: right-click on the report in the report designer window, select "Data Environment" menu item, double-click on data environment window, and write the code there, for example in the picture below.

    Define code for preparing the Bar Code ActiveX in General field

  7. The code might be a bit complex and require the use of a custom form. The code displayed in the above picture may be acquired here or download the VFP barcode example for an implementation created in VFP 6.0, which demonstrates how to store the BarCode ActiveX in the field of General type, display it on a form, and print. The sample also includes a simple code to demonstrate how to prepare the appearance and properties for the ActiveX control embedded in General Field before printing.

Code 39, UPC, EAN, or standard Code 128 or ITF fonts

Refer to the FoxPro Barcode Font Encoder Tutorial. This tutorial includes a VFP program module designed only for Code 39, Code 128, UPC, EAN, or ITF fonts. Universal, GS1-128, and DataBar fonts must use the COM ActiveX Control mentioned below. 

Integrating the COM ActiveX Control with Barcode Fonts

  1. Within VFP, a call must be made to the font encoder DLL. Pass the data that needs to be encoded in the barcode to the DLL and the DLL returns text formatted to the barcode font. Select the appropriate barcode font for the field where the formatted text is visible to generate the barcode.
  2. Refer to the ActiveX COM DLL Font Encoder for linear barcode fonts. For example, to use the Code 128 function:
    oFontGS1_128 = Createobject('IDAutomationDLL.UniversalEncoder')
    retval = oFontGS1_128.IDAutomation_Uni_Code128(DatToEncode)
  3. For all 2D barcodes such as QR Code, PDF417, and DataMatrix, refer to the COM DLL section of the User Manual of that product to obtain the DLL Reference Name and Reference Name. For example, for Data Matrix:
    TRY
    idaCom = CREATEOBJECT("IDAUTO.Datamatrix")
    CATCH
    messagebox("Error loading DLL")
    ENDTRY
    dataToEncode = "This Data is Encoded"
    textFormattedToFont = ""
    idaCom.FontEncode(dataToEncode,1,0,0, @textFormattedToFont)

If the form does not open after installing a new version of the ActiveX control

The best way to fix this problem is to install a previous version of ActiveX control again. Then open the VFP form and remember or write down all property settings for BarCode ActiveX control (right-click on the properties window and select the "Non-Default Properties Only" option that will list all properties for which values should be remembered). Remove the ActiveX control from the form and save the configuration. Close the VFP development environment. Install the new version of the ActiveX control. Open the form, put the ActiveX control on the form again, and specify property values in exactly the same way. Naturally, this will require recompiling the VFP application.

The form code may also be modified to enable the ActiveX control in code during run time, as in the VFP barcode example. If the ActiveX control is created and property values are assigned at run-time, different versions of ActiveX on the form will work with the same code.

If the Barcode ActiveX stored in fields of General type causes an error

After installing a different ActiveX control version, another program should create a new ActiveX control in the general field and set property values accordingly. This will not require recompiling the application - only the data needs to be updated.

In the VFP barcode example, there will be a sample of the report printed using a dynamically prepared ActiveX control in General fields with a sample of setting properties for it. It is recommended to use this approach so a different version of the control will not cause problems.

Special thanks to Vlad Grynchyshyn for providing information on using the Barcode ActiveX Control in FoxPro.