plug-in programmers guide8

Upload: slomljeni

Post on 01-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Plug-In Programmers Guide8

    1/36

    Retail Pro PluginsProgrammers Guide

    Table of Contents

    1.0 INTRODUCTION ................................................................................................................... 3

    2.0 ENVIRONMENT .................................................................................................................... 3 2.1 RUNNING RETAIL PRO WITH PLUGINS ........................................... .............................................. ... 3

    2.1.1 Version .......................................... .............................................. ........................................ 3 2.1.2 Files ............................................. .............................................. ......................................... 3

    2.2 DIRECTORY STRUCTURE............................................ .............................................. ...................... 3

    3.0 DEVELOPMENT ENVIRONMENT .......................................................................................... 4

    3.1 WHAT YOU NEED .......................................... .............................................. ............................... 4 3.2 SETTING UP YOUR DEVELOPMENT ENVIRONMENT ............................................ ............................... 4

    3.2.1 Install and set up Delphi .............................................. .............................................. ............. 4 3.2.2 Install and Register RDA2 ........................................... ............................................... ............ 4

    3.3.3 Make Packages Available to Delphi........................................... .............................................. ... 4 4.0 ANATOMY OF A PLUGIN ...................................................................................................... 6

    4.1 OVERVIEW ........................................... .............................................. ........................................ 6 4.2 THE PACKAGE FILE......................................... .............................................. ............................... 6 4.3 COMMON METHODS ....................................... ............................................... .............................. 6

    4.3.1 Initialize Method .............................................. ............................................... ...................... 6 4.3.2 Table Method ........................................... .............................................. ............................... 7

    4.4 THE TRPROAPP CLASS ............................................ .............................................. ...................... 8 4.4.1 CreateTableByID Method ............................................. .............................................. ............. 8 4.4.2 Preferences Method ............................................ .............................................. ...................... 8

    4.4.3 Print Method ........................................... .............................................. ............................... 9

    4.5 BASE CLASSES IN DETAIL .......................................... ............................................... ................... 10 4.5.1 TValidate............................................................................................................................ 10

    4.5.1.1 Field Method ............................................. .............................................. .................... 10 4.5.1.2 Validate Event Method ......................................... .............................................. .......... 11

    4.5.2 TAfterAssign ...................................................................................................................... 12 4.5.2.1 Execute Event Method ......................................... .............................................. .......... 12

    4.5.3 TOnUpdate ........................................................................................................................ 12 4.5.3.1 BeforeUpdate Event Method .......................................... .............................................. . 13 4.5.3.1 AfterUpdate Event Method ........................................... .............................................. . 13

    4.5.4 TItemAddRemove................................................................................................................ 13 4.5.4.1 ItemBeforeRemove Event Method ............................................. .................................... 14 4.5.4.2 ItemBeforeAdd Event Method .......................................... ............................................ 14 4.5.4.3 ItemAfterAdd Event Method ......................................... .............................................. . 14

    4.5.5 TSideButton ....................................................................................................................... 15 4.5.5.1 Menu Method ............................................ .............................................. .................... 15 4.5.5.2 Caption Method ......................................... ............................................... ................... 16 4.5.5.3 PictureFileName Method .............................................. .............................................. .. 16 4.5.5.4 Enabled Method ......................................... .............................................. ................... 16 4.5.5.5 Execute Event Method ......................................... .............................................. .......... 17

    4.5.6 TTenderChanged ................................................................................................................. 17

  • 8/9/2019 Plug-In Programmers Guide8

    2/36

    4.5.6.1 TenderScreenEntered Event Method ..................................................................................... 17 4.5.6.2 Changed Event Method ...................................................................................................... 17 4.5.7 TCustomField ..................................................................................................................... 18 4.5.7.1 FieldType Method.............................................................................................................. 18 4.5.7.2 FieldLabel Method............................................................................................................. 19 4.5.7.3 FieldDescription Method .................................................................................................... 19 4.5.7.4 MaxChars Method ............................................................................................................. 19 4.5.7.5 IsReadOnly Method ........................................................................................................... 20 4.5.7.6 LookupList Method............................................................................................................ 20 4.5.7.7 GetData Event Method ....................................................................................................... 20 4.5.7.8 SetData Event Method ....................................................................................................... 21 4.5.8 TOnPrint ........................................................................................................................... 21 4.5.8.1 BeforePrint Event Method................................................................................................... 21

    5.0 CREATING A PLUGIN ......................................................................................................... 22

    5.1 CREATE A NEW PACKAGE PROJECT .............................................. .............................................. .. 22 5.1.1 Add the plugin design-time packages to your code...................................................................... 22 5.1.2 Create a plugin class ............................................................................................................. 22

    5.1.3. Select table for the plugin...................................................................................................... 23 5.1.4 Export the plugin class .......................................................................................................... 23 5.1.5 Compile the plugin package.................................................................................................... 23

    APPENDIX A CODE LISTING OF THE RETAIL PRO API (3/2002) (FOR REFERENCE ONLY DONOT COPY THIS CODE.) .......................................................................................................... 24

    APPENDIX B EXAMPLE CODE LISTING ................................................................................. 26

    INVOICE ITEM CHANGE ........................................ ............................................... ............................ 26 InvoiceItemChange.dpk................................................................................................................. 26 uInvoiceItemChange.pas ............................................................................................................... 26

    PRINTINVOICE ........................................... .............................................. ...................................... 29

    PrintInvoice.dpk .......................................................................................................................... 29 uPrintInvoice ............................................................................................................................. 29 INVOICE BUTTON ........................................ .............................................. ...................................... 31

    InvoiceButton.dpk ....................................................................................................................... 31 uInvoiceButton.pas ...................................................................................................................... 31

    INVOICE FIELD........................................... ............................................... ...................................... 34 InvoiceField.dpk.......................................................................................................................... 34 uInvoiceField.pas......................................................................................................................... 35

  • 8/9/2019 Plug-In Programmers Guide8

    3/36

    1.0 Introduction

    A new feature in Retail Pro version 8 is the ability to use custom plugins to improve functionality andusability of Retail Pro. Plugins for Retail Pro version 8 is comparable to Custom DLLs for version 7.

    Custom plugins can be obtained through contract with RTIs Custom Programming department. However,since the plug-in API is open, anyone with sufficient knowledge about Delphi programming and Retail Pro

    can create plug-ins.

    This document is intended to give an overview of how set up the development environment and createcustom plugins.

    Before you start programming plugins you should be familiar with the following subjects:

    Delphi Plugins must be written in Borlands Delphi IDE.

    Object Oriented Programming

    Retail Data Access (RDA2) Retail Pros data is made available to the plugins through RDA2, athorough understanding of RDA2 and its object model is necessary. See separate documentation ofRDA2.

    Retail Pro Version 8

    2.0 Environment

    2.1 Running Retail Pro With Plugins

    2.1.1 Version

    You must have Retail Pro version 8.22 or above to use plug-ins. New plug-in classes become availablefrom time to time. In order to ensure complete compatibility with Retail Pro, it is recommended that youalways use the latest Retail Pro update and associated files.

    2.1.2 Files

    The files are located in the base level of the Retail Pro installation (i.e. the same level you will findRPro8.exe).

    RPro8.exe Version 8.22 or above.RDA2.dllRPRO_API.bpl

    ms_ie_d5.bplvcl50.bplvclie50.bpl

    2.2 Directory Structure

    A directory called plugins must be added to the base of the Retail Pro directory tree. Retail Pro will onlyfind and use plugin packages in this directory.

  • 8/9/2019 Plug-In Programmers Guide8

    4/36

    3.0 Development Environment

    Important : Sometimes when you open the package project files (.dpk) mentioned here with Delphi youget a message that says: This package appears to be in an older format. Would you like to convert it tothe new format?. You should always say no to this message.

    3.1 What You Need

    Borlands Delphi 5 Main development environment.RDA2 Retail Data Access version 2; a COM object library from RTI (RDA2.DLL).RPRO_API.dpk and RproAPI.pas Package and source code for the Retail Pro API.ms_ie_d5.bpl and .dcp Other run and design-time packages needed.

    3.2 Setting Up Your Development Environment

    3.2.1 Install and set up Delphi

    See product documentation from Borland for instructions on how to install Delphi.

    3.2.2 Install and Register RDA2

    Copy the file to a local directory on your computer, for example: C:\Retail\RPro\.

    Note: The RDA2.dll is automatically installed in the \Retail\RPro folder when you install Retail Pro.RDA2.dll updates are provided in the Retail Pro update zip files.

    If the RDA2.dll is already installed on your system, you will still need to register it:Run the regsvr32 program on the rda2.dll from a command prompt:Regsvr32 C:\Retail\RPro\Rda2\RDA2.dll

    Start Delphi and import the RDA2 type library.To do this click on Projects->Import Type Library on Delphis main menu.Select the RDA2 Library (Version x.x) from the list of available libraries.Make sure the box Generate Component Wrapper is un-checked and click on Create Unit.This generates the file RDA2_TLB.pas which contains Delphi-stubs for the methods contained in theRDA2.dll.Note that you should repeat this step whenever you upgrade the rda2.dll.

    3.3.3 Make Packages Available to Delphi

    The run and design time packages must be available to Delphi in order to compile Retail Pro plugins. Thiscan be done in several ways:

    For ms_ie_d5:

    1) Copy the ms_ie_d5 .bpl and .dcp files into the Delphi Bpl directory. Typically C:\ProgramFiles\Borland\Delphi5\Projects\Bpl.

    Or

    2) Copy the files to another location and add that directory to Delphis search path. The Search pathis set through Project->Options->Directories/Conditionals.

  • 8/9/2019 Plug-In Programmers Guide8

    5/36

    For RPRO_API:

    1) Open the file RPRO_API.dpk in Delphi. This should bring up the Package dialog. NOTE:sometimes the Package dialog may be hidden behind other Delphi windows (such as the codewindow), minimize these windows to find the package dialog.

    2) Click the Install button on the package dialog window. This will compile the RPRO_API and placethe results in Delphis search path.

    3) Note: To be sure you compile your plugins against the same version of the RPRO_API as RetailPro uses to run it you should find the RPRO_API.bpl file you just compilednormally located inC:\Program Files\Borland\Delphi5\Projects\bpl directoryto the base directory of your Retail Proinstallation (the same directory in which you will find RPro8.exe, for example C:\Retail ).

  • 8/9/2019 Plug-In Programmers Guide8

    6/36

    4.0 Anatomy of a Plugin

    4.1 Overview

    A plug-in is a special class contained in compiled Delphi-package (.BPL) files. There can be one or moreplug-in classes in a package file. All plug-in classes must be derived from one of the abstract base classesin the Retail Pro API (RProAPI) unit.

    Currently the following base classes are defined in the Retail Pro API:

    TValidate Catches input before it is assigned to a field in Retail Pro.TAfterAssign Is invoked after the user assigns a new value to a field.TOnUpdate Is triggered when a document is saved to disk.TItemAddRemove Is triggered when an item is added or removed from a document.TSideButton Is used to add a custom button to a context (side) menu.TTenderChanged Is called when the tender screen is entered or tender information is changed.TCustomField Add a custom field to a Retail Pro screen.TOnPrint Can be used to add custom information to a printed receipt or other document.

    Plugins typically have two kinds of methods: setup methods (prepares the plugin for work and tells RetailPro when to call it), and event methods (called by Retail Pro when a certain event happens).

    4.2 The Package File

    The package file is created as a regular Delphi package. After compilation, the resulting .bpl file is theonly file that needs to be distributed to the users of that plugin (assuming their Retail Pro environment isset up for plugins).

    As mentioned, a package file can contain one or more plugin classes, to tell Retail Pro what classes areavailable; the package exports the function RproClassesAvaliable.

    procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);begin

    RProClassArrayProc([TMyRProPlugin]);end ;

    exportsRProClassesAvailable;

    This function has one argument of type TRProClassArrayProc in which you specify which classes yourpackage contains. In the above example the package contains one plugin class called TMyRProPlugin .

    4.3 Common Methods

    All base classes have common setup methods that must be implemented in each plugin derived from it.

    4.3.1 Initialize Method

    The Initialize method is common to all base classes.

    Initialize procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual; abstract;

    Description This procedure is called when Retail Pro loads and instantiates this plugin. When thisis done depends on what table is specified for the plugin in the Table function.

  • 8/9/2019 Plug-In Programmers Guide8

    7/36

    RProApp This is a reference from Retail Pro to an object of type TRProAPP (also defined in theRProAPI unit). This object provides access to the root of the RDA2 data to theplugin. TRProAPPs single method CreateTableByID is the same as that of the IRdaDBinterface and can be used to access any table without having to create a newinstance of RDA2.

    Doc An IRdaDocument object that will point to the current document. The document is ofthe type appropriate for the table you specified in the table function.

    Note that the plugin only get a reference to the document in the Initialize function.The reference must be kept by the plugin and will automatically be updated to alwayspoint to the document for which the plugins functions are called.

    Preconditions None.

    Post Conditions The plugin class is instantiated and ready for its other methods to be called.

    Comments Use of constructors in plugins is not reliable and is not recommended. Anyconstruction code should be put in this method.

    There is no corresponding de-initialize function in the base classes. A regulardestructor can be added to the plugin if necessary, but do not forget to call inheritedfrom within it.

    4.3.2 Table Method

    The Table method is common to all classes except the TSideButton class.

    Table class function Table: integer; virtual; abstract;

    Description Since the base classes are generic and can work on any table or nested document, aplugin must implement the Table function to tell Retail Pro what specific table thisplugin will work on.

    Return Value The function must return an integer value that is the RDA2 table ID, or nested

    document ID.

    Preconditions This is a class function it may, and will, be called by Retail Pro before any objects ofthe class has been instantiated. You cannot reference any regular members from aclass function.

    Post conditions None.

    Comments Note that even though you can specify a plugin should be called for any Retail Protable, not all plugin types are appropriate for all tables. What tables a plugin is validfor is listed in each base class detailed description below.

  • 8/9/2019 Plug-In Programmers Guide8

    8/36

    4.4 The TRProApp ClassTRProApp = class

    function CreateTableByID(TableID: Integer): IRdaTable; virtual ; abstract ;function Preferences: IXMLDOMDocument; virtual ; abstract ;procedure Print(const DesignName, PrinterName: string ; SuppressPrinterDialog:

    boolean); virtual ; abstract ;end ;

    A reference to a TRProApp object is provided by Retail Pro in the Initialize method of the plugin classesthat it loads. The TRPRoAPP object is the link to Retail Pro functions and data other than the documentthat the plugin works directly on (which is usually supplied in the Doc parameter of the Initialize method).

    The TRProApp makes it possible to access other Retail Pro information through its methods.

    4.4.1 CreateTableByID Method

    This method is the same as the method with the same name in the IRdaDB interface of RDA2. Refer tothe RDA2 documentation for more information.

    CreateTableByID function CreateTableByID(TableID: Integer): IRdaTable; virtual ; abstract ;

    Description The CreateTableByID method can return a IRdaTable reference to any tableaccessible by RDA2.

    TableID An integer that corresponds to the field IDs set up in RDA2.

    Return Value An IRdaTable reference to the RDA table given by the TableID .

    4.4.2 Preferences Method

    This method is the same as the method with the same name in the IRdaDB interface of RDA2. Refer tothe RDA2 documentation for more information.

    Preferences function Preferences: IXMLDOMDocument; virtual ; abstract ;

    Description This method gives you some access to the Retail Pro preferences from within aplugin. Not that all preferences are not accessible, and the ones that are, are mostlyread-only. See the RDA documentation for information and examples of the XMLpreferences.

    Return Value An XML DOM Document object that holds information about the current Retail Propreferences.

  • 8/9/2019 Plug-In Programmers Guide8

    9/36

    4.4.3 Print Method

    Print procedure Print(const DesignName, PrinterName: string ; SuppressPrinterDialog:boolean); virtual ; abstract ;

    Description This function can be called from within a plugin to force printing of the currentdocument. Use the TOnPrint plugin to intercept and modify the information to be

    printed if necessary.DesignName A string containing the design name to be printed, if an empty string is given, Retail

    Pro will display the Design Selection dialog before printing.

    PrinterName A string containing the printer name of the destination printer. If the printer dialog isdisplayed, it will default to this printer.

    SuppressPrinterDialog If this value is set to true the printer dialog will not be displayed. Theprint job will be sent to the printer given by PrinterName , if that is notset the default system printer will be used.

  • 8/9/2019 Plug-In Programmers Guide8

    10/36

    4.5 Base Classes in Detail

    4.5.1 TValidate

    TValidate = classclass function Table: integer ; virtual ; abstract ;class function Field: integer ; virtual ; abstract ;procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual ; abstract ;

    function Validate( var Value: variant): boolean ; virtual ; abstract ;end; With the TValidate plugin class you can make plugins that can capture input and validate it before itreaches Retail Pro.

    This class can be used on any table or nested document.

    4.5.1.1 Field Method

    In addition to the Table method this class has another initialization method called Field :

    Validate class function Field: integer; virtual; abstract;

    Description Use this function to tell Retail Pro for which field you want to trap the input.

    Field An integer that corresponds to the field IDs set up in RDA2. Retail Pro will call the Validate function for all input destined for the field whos ID is returned by thisfunction.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions None.

    Comments This method is only called when a field is updated by a manual entry, not internally byRetail Pro itself.

  • 8/9/2019 Plug-In Programmers Guide8

    11/36

    4.5.1.2 Validate Event Method

    Validate function Validate(var Value: variant): boolean; virtual; abstract;

    Description This class only has one event-method. It is called before the value of any field in theselected table (or nested document) is updated.

    Note: the Doc reference obtained in the Initialize procedure will always point to thecurrent document.

    Value A variant that holds the new value proposed for the field.

    Return Value If the function returns the Boolean value True, the value in the Value parameter willbe assigned to the Retail Pro field. (Note that Retail Pro also does its own inputvalidation and not all values might be accepted). If return value is False, the inputoperation will be cancelled and the field will keep its previous value.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions The Return Value must hold a valid Boolean value.

    Comments This method is only called when a field is updated by a manual entry, not internally byRetail Pro itself.

  • 8/9/2019 Plug-In Programmers Guide8

    12/36

    4.5.2 TAfterAssign

    TAfterAssign = classclass function Table: integer ; virtual ; abstract ;procedure Initialize (RProApp: TRProApp; Doc: IRdaDocument); virtual ; abstract ;procedure Execute( const FieldID: integer ); virtual ; abstract ;

    end ;

    Plugins derived from this class will be able to act on a change in any field of the selected table or nested

    document. Its Execute function will be called after a new value is assigned to any field.

    This class can be used on any table or nested document.

    4.5.2.1 Execute Event Method

    Execute procedure Execute(const FieldID: integer); virtual; abstract;

    Description This class only has one event-method. It is called when the value of any field in theselected table (or nested document) is updated.

    Note: to get the particular document that was updated use the Doc referenceobtained in the Initialize procedure. It will always point to the current document.

    FieldID An integer holding the RDA2 field ID of the field that was updated.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post Conditions None.

    Comments This method is only called when a field is updated by a manual entry, not internally byRetail Pro itself.

    4.5.3 TOnUpdate

    TOnUpdate = classclass function Table: integer ; virtual ; abstract ;procedure Initialize (RProApp: TRProApp; Doc: IRdaDocument); virtual ; abstract ;function BeforeUpdate: boolean ; virtual ; abstract ;procedure AfterUpdate; virtual ; abstract ;

    end ;

    Plugins based on this class will be called when a document is saved to disk (for example when an invoiceis printed (or updated).

    OnUpdate plugins should only be used for tables; using it on a nested document may yield unpredictableresults and cause lock-up of Retail Pro.

  • 8/9/2019 Plug-In Programmers Guide8

    13/36

    4.5.3.1 BeforeUpdate Event Method

    BeforeUpdate function BeforeUpdate: boolean; virtual; abstract;

    Description Like the name implies, the BeforeUpdate function is called right before a document ofthe selected table is updated. From the plugin it can be decided whether thedocument should actually be updated or not.

    Return Value A Boolean value. Return True if Retail Pro is allowed to update the document. If thereturned value is False, Retail Pro will go back to where it was before the updateevent was triggered.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.The Doc reference is pointing to the document about to be updated.

    Post Conditions Return value is a valid Boolean value.

    4.5.3.1 AfterUpdate Event Method

    AfterUpdate procedure AfterUpdate; virtual; abstract;

    Description This procedure is called by Retail Pro right after a document of the selected table hasbeen saved.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.The Doc reference is pointing to the document that was just updated.

    Post conditions None

    4.5.4 TItemAddRemoveTItemAddRemove = class

    class function Table: integer ; virtual ; abstract ;procedure Initialize (RProApp: TRProApp; Doc: IRdaDocument); virtual ; abstract ;function ItemBeforeRemove: boolean ; virtual ; abstract ;function ItemBeforeAdd(ItemNo: integer ): boolean ; virtual ; abstract ;procedure ItemAfterAdd; virtual ; abstract ;

    end ;

    This class is used to create plugins that are aware of when items (nested documents) are added orremoved from a document.

    This plugin class is valid for all tables that can have items as nested documents (Invoices, SOs, POs,etc.).

    The return value of the Table function should be the ID of the RDA2 table whose documents nesteddocument adding and removing you want to trap. For example, if you want a plugin to be calledwhenever an item is added to, or removed from, an invoice, the plugins Table function should return theID number of the Invoice table.

    Note that the Doc reference received in the Initialize still points to the current document in the selectedtable (the document which is having nested documents added or removed). To access the nesteddocument which is being added or removed use the NestedDocByID or NestedDocByName methods ofthe Doc reference.

  • 8/9/2019 Plug-In Programmers Guide8

    14/36

    4.5.4.1 ItemBeforeRemove Event Method

    ItemBeforeRemove function ItemBeforeRemove: boolean; virtual; abstract;

    Description This function is called right before an item is to be removed. The plugin can decidewhether to allow it being removed or not.

    Return Value Returning the Boolean value True will allow Retail Pro to remove this item. The valueFalse will force Retail Pro to keep the item.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.There must be at east one item (nested document) added to the current document.

    Post Conditions Return value is a valid Boolean value.

    4.5.4.2 ItemBeforeAdd Event Method

    ItemBeforeAdd function ItemBeforeAdd(ItemNo: integer): boolean; virtual; abstract;

    Description This function is called right before an item is to be added. The plugin can decidewhether to allow Retail Pro to add it or not.

    ItemNo This is the Retail Pro item number of the item that is about to be added.

    Return Value If the function returns True, Retail Pro will add the item, if False the item will bediscarded.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post Conditions Return value is a valid Boolean value.

    Comments Since this is called before the item (nested document) is actually added to thedocument there is not a valid IRdaDocument representation of the item.

    4.5.4.3 ItemAfterAdd Event Method

    ItemAfterAdd procedure ItemAfterAdd; virtual; abstract;

    Description This is called immediately after an item (nested document) has been added to adocument in the selected table.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post Conditions None.

    Comments Even though this method is called when the item has already been added, some fields(for example Qty, P$, and C$) may not yet have been updated if the quantity of theadded item is larger than one.

  • 8/9/2019 Plug-In Programmers Guide8

    15/36

    4.5.5 TSideButton

    TSideButton = classclass function Menu: TSideMenu; virtual ; abstract ;procedure Initialize(RProApp: TRProApp; Doc: IRdaDocument); virtual ; abstract ;class function Caption: string; virtual ; abstract ;class function PictureFileName: string; virtual ; abstract ;function Execute: TActionRequestSet; virtual ; abstract ;function Enabled: boolean ; virtual ; abstract ;

    end ;

    This plugin enables you to add a custom button to a context (side) menu in Retail Pro.

    In addition to the Initialize method, this class has four other initialization methods: Menu , Caption ,PictureFileName , and Enabled .

    4.5.5.1 Menu Method

    Menu class function Menu: TSideMenu; virtual; abstract;

    Description This function controls to which context menu the button should be added.

    Return Value A value of type TSideMenu that tells Retail Pro to which menu the button should beadded. Currently the following values are possible:smDepartmentssmVendorssmCustomerssmInventorysmReceiptssmReceiptListsmVoucherssmVoucherListsmMemossmMemoList

    smSlipsmSlipListsmSOsmSOListsmPOsmPOListsmTOsmTOListsmTender

    Note: for screens where Form view and List view have different menus there areTSideMenu types for both menus respectively. For example, smRecipts corresponds tothe menu for Receipts in Form view, and smReceiptList to the menu for Receipts in

    List view.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions Return value is a TSideMenu value.

  • 8/9/2019 Plug-In Programmers Guide8

    16/36

    4.5.5.2 Caption Method

    Caption class function Caption: string; virtual; abstract;

    Description This function tells Retail Pro what the caption of the custom button should be.

    Return Value Return the desired Caption for the button as a string.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.There must be at east one item (nested document) added to the current document.

    Post conditions Return value is a valid string.

    4.5.5.3 PictureFileName Method

    PictureFileName class function PictureFileName: string; virtual; abstract

    Description Use this function to add a bitmap (.bmp) to the custom button.

    Return Value Return the desired filename of the bitmap for the button as a string.If no path is given Retail Pro will look for the bitmap in the /Plugins directory.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.There must be at east one item (nested document) added to the current document.

    Post conditions Return value is a valid string pointing to a valid bitmap file.

    4.5.5.4 Enabled Method

    Enabled function Enabled: boolean; virtual; abstract;

    Description Tells Retail Pro whether the button is enabled or disabled (grayed out). Retail Procalls this function periodically when it is idle so unlike the other properties of thebutton (Caption, Bitmap) Enabled can be changed at any time during execution.

    Return Value Return True for the button to be enabled, False for disabled.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.There must be at east one item (nested document) added to the current document.

    Post conditions Return value is a valid Boolean value.

  • 8/9/2019 Plug-In Programmers Guide8

    17/36

    4.5.5.5 Execute Event Method

    Execute function Execute: TActionRequestSet; virtual; abstract;

    Description This function is called from Retail Pro when the user clicked the custom button.

    Return Value The return value is of type TactionRequestSet, currently the options in this set are:

    arRefreshDocumentarRefreshList

    The return value forces Retail Pro to update the view of the current document or listto make sure any changes made during the execute method are displayed.

    Return arRefreshList if your button is on a list menu, and arRefreshDocument if yourbutton is on a regular menu.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.There must be at east one item (nested document) added to the current document.

    Post conditions Return value is a valid TactionRequestSet value.

    4.5.6 TTenderChanged

    TTenderChanged = classprocedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;procedure TenderScreenEntered; virtual ; abstract ;procedure Changed; virtual ; abstract ;

    end ; The TTenderChanged plugin allows you to trap when the tender screen is entered and when the tenderinformation is changed (for example when a tender line is added or deleted to the tender screen).

    This class has two event methods: TenderScreenEntered and Changed .

    4.5.6.1 TenderScreenEntered Event Method

    TenderScreenEntered procedure TenderScreenEntered; virtual ; abstract ;

    Description Is called by Retail Pro whenever the user enters the Tender screen, for example whentendering a new invoice.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions None.

    4.5.6.2 Changed Event Method

    Changed procedure Changed; virtual ; abstract ;

    Description Is called by Retail Pro whenever the user changes the information on the tenderscreen. When a tender line is added or deleted.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions None.

  • 8/9/2019 Plug-In Programmers Guide8

    18/36

    4.5.7 TCustomField

    TCustomField = classclass function Table: integer; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual; abstract;class function FieldType: TCustomFieldType; virtual ; abstract ;class function FieldLabel: string; virtual ; abstract ;class function FieldDescription: string ; virtual ; abstract ;function MaxChars: integer; virtual ; abstract ; // 0 for unlimitedfunction IsReadOnly: boolean; virtual ; abstract ;function GetData: variant; virtual ; abstract ;procedure SetData(Value: variant); virtual ; abstract ;function LookupList: string ; virtual ; abstract ;

    end ; With this plugin you can add a custom field to a Retail Pro screen, for example an invoice. It can be usedon both regular and nested documents. The value of the field is not stored in the Retail Pro database soit is up to the plugin itself to save and retrieve values and associate them with the correct document ifnecessary.

    Along with Initialize and Table this plugin class has 8 setup related methods: FieldType , FieldLabel ,

    FieldDescription , MaxChars , IsReadOnly , and LookupList . The event methods are GetData and SetData .

    4.5.7.1 FieldType Method

    FieldType class function FieldType: TCustomFieldType; virtual ; abstract ;

    Description Tells Retail Pro what type of field this is so it can be formatted correctly on screen.

    Return Value Return a value of the type TCustomFieldType. This type can have the following valuesare possible:cftStringcftIntegercftDoublecftQuantitycftCurrencycftDatecftTimecftDateTime

    Preconditions This is a class function it may, and will, be called by Retail Pro before any objects ofthe class has been instantiated. You cannot reference any regular members from thisfunction.

    Post conditions The return value is a valid TCustomFieldType Value.

  • 8/9/2019 Plug-In Programmers Guide8

    19/36

    4.5.7.2 FieldLabel Method

    FieldLabel class function FieldLabel: string; virtual ; abstract ;

    Description Tells Retail Pro what the label to display for the field.

    Return Value Return a string value containing the desired label.

    Preconditions This is a class function it may, and will, be called by Retail Pro before any objects ofthe class has been instantiated. You cannot reference any regular members from thisfunction.

    Post conditions The return value is a valid, non-empty string.

    4.5.7.3 FieldDescription Method

    FieldDescription class function FieldDescription: string; virtual ; abstract ;

    Description Tells Retail Pro what the description is for the field. The description is displayed in the Tool Tips window when the cursor is placed over the field for a specified amount oftime.

    Return Value Return a string value containing the desired description.

    Preconditions This is a class function it may, and will, be called by Retail Pro before any objects ofthe class has been instantiated. You cannot reference any regular members from thisfunction.

    Post conditions The return value is a valid string.

    4.5.7.4 MaxChars MethodMaxChars function MaxChars: integer; virtual ; abstract ;

    Description Sets the maximum number of characters that retail pro will allow to be entered in thecustom field.

    Return Value Return an integer value representing the maximum number of characters. Return zeroto set an unlimited field length.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions The return value is a valid integer value.

  • 8/9/2019 Plug-In Programmers Guide8

    20/36

    4.5.7.5 IsReadOnly Method

    IsReadOnly function IsReadOnly: boolean; virtual ; abstract ;

    Description If this function is set to true, Retail Pro will not allow the user to edit this field.

    Return Value Return an bolean value of true to disallow editing of the field.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions The return value is a valid boolean value.

    4.5.7.6 LookupList Method

    LookupList function LookupList: string ; virtual ; abstract ;

    Description If you want to have certain pre-selected values available for the field through a dropdown list, you can set up the list of values with this function.

    Return Value Return a string of comma-separated values that you want to appear in the drop downlist. If an empty string is returned there will be no drop down list for the field.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions The return value is a valid string value.

    4.5.7.7 GetData Event Method

    GetData function GetData: variant; virtual ; abstract ;

    Description This function is called when Retail Pro is going to display the content of the customfield. This function supplies the value that should be displayed to Retail Pro.

    Return Value Return a variant type with the value that Retail Pro should display.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions The return value is a valid variant value with a variant type that can be converted anddisplayed according to the FieldType .

  • 8/9/2019 Plug-In Programmers Guide8

    21/36

    4.5.7.8 SetData Event Method

    SetData procedure SetData(Value: variant); virtual ; abstract ;

    Description This function is called when Retail Pro is going to set the value of the custom field.I.e. when the user has entered a new value for the field. Note that the new valuemust not necessarily be saved; Retail Pro will call GetData immediately after this

    method is finished so if the new value is not saved (for example because it did notpass validation) the old value will overwrite the new value.This method will never be called if the field is set to read-only.

    Value A parameter of variant type that contains the new value that the userentered/selected.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.

    Post conditions None.

    4.5.8 TOnPrint

    TOnPrint = classclass function Table: integer; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual ; abstract ;

    end ; The TOnPrint class can be used to intercept when a document is about to b printed, from its eventmethod BeforePrint it is possible to change the information that will be printed.

    See the RTI document titled V8 Custom Documents for information about how to process theDocument Printer XML to print custom documents.

    4.5.8.1 BeforePrint Event Method

    BeforePrint procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual ; abstract ;

    Description Called just before a document is printed.

    XMLDoc A XML DOM Document containing the information that will be sent to the DocumentPrinter. This information may be modified to produce a customized print out. Ifnothing is changed in the XMLDoc, the document will be printed in normal fashion.

    Preconditions Retail Pro must have called Initialize on this class before this method can be invoked.The XMLDoc parameter references a valid XML Dom Document object containing thedocument information to be printed.

    Post conditions The XMLDoc parameter references a valid XML Dom Document object containing thedocument information to be printed.

  • 8/9/2019 Plug-In Programmers Guide8

    22/36

    5.0 Creating a Plugin

    The easiest way the create a plugin package is to simply copy one of the examples provided by RTI andmodify them to suit your needs. However, if you want to create a plugin package from scratch, this iswhat you do:

    5.1 Create a New Package ProjectFrom Delphis main menu select File->New . From the New Items dialog box, make sure you have the tablabeled New selected and double-click on the Package icon.

    When the new package is open select File->Save All and select a location and name for your project files.

    5.1.1 Add the plugin design-time packages to your code

    Add RProAPI and RDA2_TLB to the uses clause of your code.

    5.1.2 Create a plugin class

    All plugin classes must be inherited from one of the abstract base classes defined in the Retail Pro API(RProAPI) unit. These classes are described in detail later in this document. Make sure you override all ofthe abstract methods in the class.

    Example:type

    TInvcUpdate = class (TOnUpdate)private

    fInvoice: IRdaDocument;public

    class function Table: integer ; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;function BeforeUpdate: boolean ; override ;procedure AfterUpdate; override ;

    end ;

  • 8/9/2019 Plug-In Programmers Guide8

    23/36

    5.1.3. Select table for the plugin

    The Table function tells Retail Pro when to call a certain plugin. In this example it will be called for theInvoices table.

    class function TInvcUpdate.Table: integer ;begin

    Result := tblInvoices;end ;

    5.1.4 Export the plugin class

    Each plugin package must export an RproClassesAvaliable procedure. This procedure tells Retail Pro whatclasses are available inside the package.

    procedure RProClassesAvailable(RProClassArrayProc:TRProClassArrayProc);begin

    RProClassArrayProc([TInvcUpdate]);end ;

    5.1.5 Compile the plugin packageTo compile a Delphi package you must click the Compile button on the package manager window ratherthan using the Compile command off the main menu.

    After a successful compilation, place the resulting .bpl file in the plugins directory under the Retail Prodirectory.

  • 8/9/2019 Plug-In Programmers Guide8

    24/36

    Appendix A Code listing of the Retail Pro API (3/2002)(For Reference ONLY DO NOT COPY THIS CODE.)unit RProAPI;

    interface

    usesRDA2_TLB;

    const AllFields = -100;csClassesAvailableName = 'RProClassesAvailable';

    typeTRProClassArrayProc = procedure (Classes: array of TClass);TRProClassesAvailableProc = procedure (RProClassArrayProc: TRProClassArrayProc);

    TSideMenu = (smDepartments, smVendors, smCustomers, smInventory,smReceipts, smReceiptList,smVouchers, smVoucherList,smMemos, smMemoList,smSlip, smSlipList,smSO, smSOList,smPO, smPOList,smTO, smTOList,smTender);

    TActionRequest = (arRefreshDocument, arRefreshList);TActionRequestSet = set of TActionRequest;

    TCustomFieldType = (cftString, cftInteger, cftDouble, cftQuantity, cftCurrency,cftDate, cftTime, cftDateTime);

    TRProApp = classfunction CreateTableByID(TableID: Integer ): IRdaTable; virtual ; abstract ;

    function Preferences: IXMLDOMDocument; virtual; abstract;procedure Print(const DesignName, PrinterName: string; SuppressPrinterDialog:boolean); virtual; abstract;

    end ;

    TValidateClass = class of TValidate;TValidate = class

    class function Table: integer ; virtual ; abstract ;class function Field: integer ; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;function Validate( var Value: variant): boolean; virtual ; abstract ;

    end ;

    TAfterAssignClass = class of TAfterAssign;TAfterAssign = class

    class function Table: integer; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;procedure Execute( const FieldID: integer ); virtual ; abstract ;

    end ;

    TOnUpdateClass = class of TOnUpdate;TOnUpdate = class

    class function Table: integer ; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;function BeforeUpdate: boolean; virtual ; abstract ;procedure AfterUpdate; virtual ; abstract ;

    end ;

  • 8/9/2019 Plug-In Programmers Guide8

    25/36

    TItemAddRemoveClass = class of TItemAddRemove;TItemAddRemove = class

    class function Table: integer ; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;function ItemBeforeRemove: boolean; virtual ; abstract ;function ItemBeforeAdd(ItemNo: integer ): boolean; virtual ; abstract ;procedure ItemAfterAdd; virtual ; abstract ;

    end ;

    TSideButtonClass = class of

    TSideButton;TSideButton = classclass function Menu: TSideMenu; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;class function Caption: string; virtual ; abstract ;class function PictureFileName: string; virtual ; abstract ;function Execute: TActionRequestSet; virtual ; abstract ;// Enabled is called constantly (when RPro is idle),// so it shouldn't be time-consumingfunction Enabled: boolean; virtual ; abstract ;

    end ;

    TTenderChangedClass = class of TTenderChanged;TTenderChanged = class

    procedure Initialize(RProApp: TRProApp;Doc: IRdaDocument); virtual ; abstract ;

    procedure TenderScreenEntered; virtual ; abstract ;procedure Changed; virtual ; abstract ;end ;

    TOnPrintClass = class of TOnPrint;TOnPrint = class

    class function Table: integer; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;procedure BeforePrint(XMLDoc: IXMLDOMDocument); virtual ; abstract ;

    end ;

    TCustomFieldClass = class of TCustomField;TCustomField = class

    class function Table: integer; virtual ; abstract ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); virtual ; abstract ;class function FieldType: TCustomFieldType; virtual ; abstract ;class function FieldLabel: string ; virtual ; abstract ;

    class function FieldDescription: string ; virtual ; abstract ;function MaxChars: integer; virtual ; abstract ; // 0 for unlimitedfunction IsReadOnly: boolean; virtual ; abstract ;function GetData: variant; virtual ; abstract ;

    procedure SetData(Value: variant); virtual ; abstract ;function LookupList: string ; virtual ; abstract ;

    end ;

    implementation

    initializationend .

  • 8/9/2019 Plug-In Programmers Guide8

    26/36

    Appendix B Example Code Listing

    Invoice Item Change

    InvoiceItemChange.dpk

    package InvoiceItemChange;

    {$R *.RES}{$ALIGN ON}{$ASSERTIONS ON}{$BOOLEVAL OFF}{$DEBUGINFO ON}{$EXTENDEDSYNTAX ON}{$IMPORTEDDATA ON}{$IOCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRINGS ON}{$OPENSTRINGS ON}{$OPTIMIZATION OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEINFO ON}{$SAFEDIVIDE OFF}{$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRINGCHECKS ON}{$WRITEABLECONST OFF}{$MINENUMSIZE 1}{$IMAGEBASE $400000}{$RUNONLY}{$IMPLICITBUILD OFF}

    requiresvcl50,RPRO_API;

    containsuInvoiceItemChange;

    end .

    uInvoiceItemChange.pas

    unit uInvoiceItemChange;

    interface

    usesRProAPI, RDA2_TLB, Dialogs, SysUtils;

    typeTInvcItemNumAssigned = class (TAfterAssign)private

    fInvoice: IRdaDocument;

    fInvoiceItem: IRdaDocument;fCustomers: IRdaTable;public

    class function Table: integer ; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;procedure Execute( const FieldID: integer ); override ;

    end ;

    TInvcItemAddRemove = class (TItemAddRemove)private

    fInvoice: IRdaDocument;fInvoiceItem: IRdaDocument;

    public

  • 8/9/2019 Plug-In Programmers Guide8

    27/36

    class function Table: integer ; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;function ItemBeforeRemove: boolean ; override ;function ItemBeforeAdd(ItemNo: integer ): boolean ; override ;procedure ItemAfterAdd; override ;

    end ;

    TInvcItemNumValidate = class (TValidate)privatepublic

    class function Table: integer ; override ;class function Field: integer ; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;function Validate( var Value: variant): boolean; override ;

    end;

    implementation

    procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);begin

    RProClassArrayProc([TInvcItemNumAssigned, TInvcItemAddRemove , TInvcItemNumValidate]);end ;

    exportsRProClassesAvailable;

    { TInvcItemNumAssigned }

    class function TInvcItemNumAssigned.Table: integer ;begin

    Result := ntblInvoiceItems;end ;

    procedure TInvcItemNumAssigned.Initialize(RProApp: TRProApp; Doc: IRdaDocument);begin

    fInvoice := Doc;fInvoiceItem := fInvoice.NestedDocByID[ntblInvoiceItems];fCustomers := RProApp.CreateTableByID(tblCustomers);fCustomers.Open;fCustomers.ActiveIndexID := idxCustSID;

    end ;

    procedure TInvcItemNumAssigned.Execute( const FieldID: integer );varIsNull: WordBool;

    beginif FieldID = fidQty then

    fInvoiceItem.SetDouble(fInvoiceItem.GetDouble(fidQty, IsNull) + 1, fidQty);if fCustomers.Find(fInvoice.GetString(fidBillToCustSID, IsNull), true) then

    ShowMessage(fCustomers.Document.GetString(fidFullName ,IsNull));end ;

    { TInvcItemAddRemove }

    class function TInvcItemAddRemove.Table: integer ;begin

    Result := tblInvoices;end ;

    procedure TInvcItemAddRemove.Initialize(RProApp: TRProApp;Doc: IRdaDocument);begin

    fInvoice := Doc;fInvoiceItem := fInvoice.NestedDocByID[ntblInvoiceItems];

    end ;

    function TInvcItemAddRemove.ItemBeforeRemove: boolean;var

    IsNull: WordBool;ItemNo: integer;

    beginItemNo := fInvoiceItem.GetInteger(fidItemNo, IsNull);Result := true;

  • 8/9/2019 Plug-In Programmers Guide8

    28/36

    if ItemNo = 2 thenbegin

    Result := false;ShowMessage(Format('Item # %d cannot be removed', [ItemNo]));

    endelse

    ShowMessage(Format('Item # %d is removed', [ItemNo]));end ;

    function TInvcItemAddRemove.ItemBeforeAdd(ItemNo: integer ): boolean ;begin

    Result := true;if ItemNo = 3 thenbegin

    Result := false;ShowMessage(Format('Item # %d cannot be added', [ItemNo]));

    end ;end ;

    procedure TInvcItemAddRemove.ItemAfterAdd;var

    IsNull: WordBool;begin

    ShowMessage(Format('Item # %d is added', [fInvoiceItem.GetInteger(fidItemNo, IsNull)]));end ;

    { TInvcItemNumValidate }

    class function TInvcItemNumValidate.Table: integer ;begin

    Result := ntblInvoiceItems;end ;

    class function TInvcItemNumValidate.Field: integer ;begin

    Result := fidItemLookup;end ;

    procedure TInvcItemNumValidate.Initialize(RProApp: TRProApp; Doc: IRdaDocument);beginend ;

    function TInvcItemNumValidate.Validate( var Value: variant): boolean;begin

    Result := true;case Value of4:begin

    Result := false;ShowMessage('Item # 4 rejected');

    end ;5:begin

    Value := 6;ShowMessage('Item # 5 replaced with Item # 6');

    end ;end ;

    end ;

    end .

  • 8/9/2019 Plug-In Programmers Guide8

    29/36

    PrintInvoice

    PrintInvoice.dpk

    package PrintInvoice;

    {$R *.RES}{$ALIGN ON}

    {$ASSERTIONS ON}{$BOOLEVAL OFF}{$DEBUGINFO ON}{$EXTENDEDSYNTAX ON}{$IMPORTEDDATA ON}{$IOCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRINGS ON}{$OPENSTRINGS ON}{$OPTIMIZATION OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEINFO ON}{$SAFEDIVIDE OFF}{$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRINGCHECKS ON}

    {$WRITEABLECONST OFF}{$MINENUMSIZE 1}{$IMAGEBASE $400000}{$IMPLICITBUILD OFF}

    requiresvcl50,RPRO_API;

    containsuPrintInvoice;

    end . uPrintInvoice

    unit uPrintInvoice;

    interface

    usesWindows, RProAPI, RDA2_TLB, Dialogs, SysUtils, MSXML_TLB, ShellAPI;

    typeTInvcUpdate = class (TOnUpdate)private

    fInvoice: IRdaDocument;public

    class function Table: integer; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;function BeforeUpdate: boolean; override ;procedure AfterUpdate; override ;

    end ;

    TInvoicePrint = class (TOnPrint)private

    fInvoice: IRdaDocument;public

    class function Table: integer; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;procedure BeforePrint(XMLDoc: IXMLDOMDocument); override ;

    end ;

    implementation

  • 8/9/2019 Plug-In Programmers Guide8

    30/36

    procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);begin

    RProClassArrayProc([TInvcUpdate]);end ;

    exportsRProClassesAvailable;

    { TInvcUpdate }

    class function TInvcUpdate.Table: integer ;begin

    Result := tblInvoices;end ;

    procedure TInvcUpdate.Initialize(RProApp: TRProApp; Doc: IRdaDocument);begin

    fInvoice := Doc;end ;

    function TInvcUpdate.BeforeUpdate: boolean ;var

    IsNull: wordbool;begin

    if fInvoice.GetDouble(fidTotal, IsNull) > 100 thenbegin

    Result := false;ShowMessage('Receipts > $100 are not allowed');endelse

    Result := true;end ;

    procedure TInvcUpdate.AfterUpdate;var

    XMLInvoice: IXMLDOMDocument;begin

    XMLInvoice := fInvoice.XMLDOMDocument(false);XMLInvoice.save('invoice.xml');ShellExecute(0, 'open', 'invoice.xml', '', '', SW_SHOWNORMAL);DeleteFile('invoice.xml');

    end ; { TInvoicePrint }

    class function TInvoicePrint.Table: integer;begin

    Result := tblInvoices;end ;

    procedure TInvoicePrint.Initialize(RProApp: TRProApp; Doc: IRdaDocument);begin

    fInvoice := Doc;end ;

    procedure TInvoicePrint.BeforePrint(XMLDoc: IXMLDOMDocument);begin

    XMLDoc.documentElement.setAttribute('PI', 3.14);end ;

    end .

  • 8/9/2019 Plug-In Programmers Guide8

    31/36

    InvoiceButton

    InvoiceButton.dpk

    package InvoiceButton;

    {$R *.RES}{$ALIGN ON}{$ASSERTIONS ON}{$BOOLEVAL OFF}{$DEBUGINFO ON}{$EXTENDEDSYNTAX ON}{$IMPORTEDDATA ON}{$IOCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRINGS ON}{$OPENSTRINGS ON}{$OPTIMIZATION OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEINFO ON}

    {$SAFEDIVIDE OFF}{$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRINGCHECKS ON}{$WRITEABLECONST OFF}{$MINENUMSIZE 1}{$IMAGEBASE $400000}{$RUNONLY}{$IMPLICITBUILD OFF}

    requiresvcl50,RPRO_API;

    containsuInvoiceButton;

    end . uInvoiceButton.pas

    unit uInvoiceButton;

    interface

    usesWindows, RProAPI, RDA2_TLB, SysUtils;

    typeTInvoiceButton = class (TSideButton)Private

    fRProApp: TRProApp;fInvoice: IRdaDocument;

    publicclass function Menu: TSideMenu; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;class function Caption: string; override ;class function PictureFileName: string; override ;function Execute: TActionRequestSet; override ;function Enabled: boolean; override ;

    end ;

    TTenderButton = class (TSideButton)private

  • 8/9/2019 Plug-In Programmers Guide8

    32/36

    fInvoice: IRdaDocument;public

    class function Menu: TSideMenu; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;class function Caption: string ; override ;class function PictureFileName: string ; override ;function Execute: TActionRequestSet; override ;function Enabled: boolean; override ;

    end ;

    TTenderMonitor = class (TTenderChanged)private

    fTender: IRdaTender;public

    procedure Initialize(RProApp: TRProApp;Doc: IRdaDocument); override ;

    procedure TenderScreenEntered; override ;procedure Changed; override ;

    end ;

    implementation

    procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);begin

    RProClassArrayProc([TInvoiceButton]);end ;

    exportsRProClassesAvailable;

    { TInvoiceButton }

    class function TInvoiceButton.Menu: TSideMenu;begin

    Result := smReceipts;end ;

    class function TInvoiceButton.Caption: string;begin

    Result := 'Custom Button';end ;

    procedure TInvoiceButton.Initialize(RProApp: TRProApp; Doc: IRdaDocument);beginfRProApp := RproApp;

    fInvoice := Doc;end ;

    function TInvoiceButton.Execute: TActionRequestSet;begin

    // \\CORDELIA\RD1fRProApp.Print('Receipt, Letter', '', false);fInvoice.SetString('Custom Comment', fidInvcComment1);Result := [arRefreshDocument];

    end ;

    class function TInvoiceButton.PictureFileName: string;begin

    Result := 'global discount.bmp';end ;

    function TInvoiceButton.Enabled: boolean;var

    h, m, sec, msec: word;begin

    DecodeTime(Time, h, m, sec, msec);Result := sec < 50;

    end ;

    { TTenderButton }

    class function TTenderButton.Menu: TSideMenu;begin

    Result := smTender;

  • 8/9/2019 Plug-In Programmers Guide8

    33/36

    end ;

    class function TTenderButton.Caption: string ;begin

    Result := 'Credit 2 Dollars';end ;

    procedure TTenderButton.Initialize(RProApp: TRProApp; Doc: IRdaDocument);begin

    fInvoice := Doc;end

    ;function TTenderButton.Execute: TActionRequestSet;var

    Tender: IRdaTender;Card: IRdaCreditCard;TndrItem: IDispatch;

    beginTender := fInvoice.CustomInterface as IRdaTender;TndrItem := Tender.AddItem(ttCreditCard);Card := TndrItem as IRdaCreditCard;

    // Card.Amount := 2;Card.CardType := 'VISA';Card.CardNumber := '12345';Card.ExpMonth := 9;Card.ExpYear := 03;Result := [arRefreshDocument];

    end ;class function TTenderButton.PictureFileName: string ;begin

    Result := 'global discount.bmp';end ;

    function TTenderButton.Enabled: boolean ;begin

    Result := true;end ;

    { TTenderMonitor }

    procedure TTenderMonitor.Initialize(RProApp: TRProApp; Doc: IRdaDocument);begin

    fTender := Doc.CustomInterface as IRdaTender;end ;procedure TTenderMonitor.TenderScreenEntered;begin

    ShowMessage('Tenders entered');end ;

    procedure TTenderMonitor.Changed;var

    Item: IUnknown;fc: IRdaFC;

    beginShowMessage(IntToStr(fTender.TenderItems.length));if fTender.Undefined < 0 thenbegin

    Item := fTender.AddItem(ttFC);fc := Item as IRdaFC;fc.Amount := fTender.Undefined;fc.FCAmount := 1000;fc.FCName := 'ROUBLES';

    end ;end ; end .

  • 8/9/2019 Plug-In Programmers Guide8

    34/36

    InvoiceField

    InvoiceField.dpk

    package InvoiceField;

    {$R *.RES}{$ALIGN ON}

    {$ASSERTIONS ON}{$BOOLEVAL OFF}{$DEBUGINFO ON}{$EXTENDEDSYNTAX ON}{$IMPORTEDDATA ON}{$IOCHECKS ON}{$LOCALSYMBOLS ON}{$LONGSTRINGS ON}{$OPENSTRINGS ON}{$OPTIMIZATION OFF}{$OVERFLOWCHECKS OFF}{$RANGECHECKS OFF}{$REFERENCEINFO ON}{$SAFEDIVIDE OFF}{$STACKFRAMES OFF}{$TYPEDADDRESS OFF}{$VARSTRINGCHECKS ON}

    {$WRITEABLECONST OFF}{$MINENUMSIZE 1}{$IMAGEBASE $400000}{$IMPLICITBUILD OFF}

    requiresvcl50,RPRO_API;

    containsuInvoiceField;

    end .

  • 8/9/2019 Plug-In Programmers Guide8

    35/36

    uInvoiceField.pas

    unit uInvoiceField;

    interface

    usesWindows, Classes, RProAPI, RDA2_TLB, Dialogs, SysUtils, MSXML_TLB, ShellAPI;

    typeTInvcWrappingKind = class (TCustomField)private

    fInvoice: IRdaDocument;fData: TStringList;

    publicclass function Table: integer; override ;procedure Initialize(RProApp: TRProApp;

    Doc: IRdaDocument); override ;destructor Destroy; override ;class function FieldType: TCustomFieldType; override ;class function FieldLabel: string ; override ;class function FieldDescription: string ; override ;function MaxChars: integer; override ;function IsReadOnly: boolean; override ;function GetData: variant; override ;procedure SetData(Value: variant); override ;

    function LookupList: string; override ;end ;

    implementation

    constcsFileName = 'wrappings.txt';

    procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);begin

    RProClassArrayProc([TInvcWrappingKind]);end ;

    exportsRProClassesAvailable;

    { TInvcWrappingKind }

    class function TInvcWrappingKind.Table: integer;begin

    Result := tblInvoices;end ;

    procedure TInvcWrappingKind.Initialize(RProApp: TRProApp; Doc: IRdaDocument);begin

    fInvoice := Doc;fData := TStringList.Create;try

    fData.LoadFromFile(csFileName);exceptend ;

    end ;

    destructor TInvcWrappingKind.Destroy;begin

    fData.SaveToFile(csFileName);fData.Free;inherited ;

    end ;

    class function TInvcWrappingKind.FieldLabel: string ;begin

    Result := 'Wrapping';end ;

    class function TInvcWrappingKind.FieldDescription: string ;begin

    Result := 'Wrapping type used for the Receipt';

  • 8/9/2019 Plug-In Programmers Guide8

    36/36

    end ;

    class function TInvcWrappingKind.FieldType: TCustomFieldType;begin

    Result := cftString;end ;

    function TInvcWrappingKind.IsReadOnly: boolean;var

    IsNull: WordBool;begin

    Result := fInvoice.GetInteger(fidBillToCustID, IsNull) = 0; //allow only Receipts with customerend ;

    function TInvcWrappingKind.MaxChars: integer;begin

    Result := 0;end ;

    function TInvcWrappingKind.GetData: variant;var

    IsNull: WordBool;begin

    Result := fData.Values[IntToStr(fInvoice.GetInteger(fidInvcNum, IsNull))];end ;

    procedure TInvcWrappingKind.SetData(Value: variant);

    var IsNull: WordBool;begin

    fData.Values[IntToStr(fInvoice.GetInteger(fidInvcNum, IsNull))] := Value;end ;

    function TInvcWrappingKind.LookupList: string ;begin

    Result := 'Birthday,Christmas,Valentine';end ;

    end .