Sie sind auf Seite 1von 36

Retail Pro Plugins

Programmers 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

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 DO
NOT 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
INVOICEBUTTON ............................................................................................................................ 31
InvoiceButton.dpk ....................................................................................................................... 31
uInvoiceButton.pas ...................................................................................................................... 31
INVOICEFIELD ................................................................................................................................ 34
InvoiceField.dpk .......................................................................................................................... 34
uInvoiceField.pas ......................................................................................................................... 35

1.0 Introduction
A new feature in Retail Pro version 8 is the ability to use custom plugins to improve functionality and
usability 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 create
custom 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, a
thorough understanding of RDA2 and its object model is necessary. See separate documentation of
RDA2.

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 available
from time to time. In order to ensure complete compatibility with Retail Pro, it is recommended that you
always 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 find
RPro8.exe).
RPro8.exe Version 8.22 or above.
RDA2.dll
RPRO_API.bpl
ms_ie_d5.bpl
vcl50.bpl
vclie50.bpl

2.2 Directory Structure


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

3.0 Development Environment


Important: Sometimes when you open the package project files (.dpk) mentioned here with Delphi you
get a message that says: This package appears to be in an older format. Would you like to convert it to
the 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 the
RDA2.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. This
can 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:\Program
Files\Borland\Delphi5\Projects\Bpl.

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

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 code
window), 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 place
the results in Delphis search path.
3) Note: To be sure you compile your plugins against the same version of the RPRO_API as Retail
Pro uses to run it you should find the RPRO_API.bpl file you just compilednormally located in
C:\Program Files\Borland\Delphi5\Projects\bpl directoryto the base directory of your Retail Pro
installation (the same directory in which you will find RPro8.exe, for example C:\Retail).

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 more
plug-in classes in a package file. All plug-in classes must be derived from one of the abstract base classes
in 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 Retail
Pro 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 the
only file that needs to be distributed to the users of that plugin (assuming their Retail Pro environment is
set up for plugins).
As mentioned, a package file can contain one or more plugin classes, to tell Retail Pro what classes are
available; the package exports the function RproClassesAvaliable.
procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);
begin
RProClassArrayProc([TMyRProPlugin]);
end;
exports
RProClassesAvailable;

This function has one argument of type TRProClassArrayProc in which you specify which classes your
package 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 this
is done depends on what table is specified for the plugin in the Table function.

RProApp

This is a reference from Retail Pro to an object of type TRProAPP (also defined in the
RProAPI unit). This object provides access to the root of the RDA2 data to the
plugin. TRProAPPs single method CreateTableByID is the same as that of the IRdaDB
interface and can be used to access any table without having to create a new
instance of RDA2.

Doc

An IRdaDocument object that will point to the current document. The document is of
the 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 always
point 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. Any


construction code should be put in this method.
There is no corresponding de-initialize function in the base classes. A regular
destructor can be added to the plugin if necessary, but do not forget to call inherited
from 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, a
plugin must implement the Table function to tell Retail Pro what specific table this
plugin 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 of
the class has been instantiated. You cannot reference any regular members from a
class function.

Post conditions None.


Comments

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

4.4 The TRProApp Class


TRProApp = 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 classes
that it loads. The TRPRoAPP object is the link to Retail Pro functions and data other than the document
that 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 to
the RDA2 documentation for more information.
CreateTableByID

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

Description

The CreateTableByID method can return a IRdaTable reference to any table


accessible 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 to
the 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 a
plugin. Not that all preferences are not accessible, and the ones that are, are mostly
read-only. See the RDA documentation for information and examples of the XML
preferences.

Return Value

An XML DOM Document object that holds information about the current Retail Pro
preferences.

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 current
document. 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 is
displayed, it will default to this printer.

SuppressPrinterDialog

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

4.5 Base Classes in Detail


4.5.1 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;

With the TValidate plugin class you can make plugins that can capture input and validate it before it
reaches 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 this
function.

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 by
Retail Pro itself.

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 the
selected table (or nested document) is updated.
Note: the Doc reference obtained in the Initialize procedure will always point to the
current 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 will
be assigned to the Retail Pro field. (Note that Retail Pro also does its own input
validation and not all values might be accepted). If return value is False, the input
operation 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 by
Retail Pro itself.

4.5.2 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;

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 the
selected table (or nested document) is updated.
Note: to get the particular document that was updated use the Doc reference
obtained 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 by
Retail Pro itself.

4.5.3 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;

Plugins based on this class will be called when a document is saved to disk (for example when an invoice
is printed (or updated).
OnUpdate plugins should only be used for tables; using it on a nested document may yield unpredictable
results and cause lock-up of Retail Pro.

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 of
the selected table is updated. From the plugin it can be decided whether the
document should actually be updated or not.

Return Value

A Boolean value. Return True if Retail Pro is allowed to update the document. If the
returned value is False, Retail Pro will go back to where it was before the update
event 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 has
been 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 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;

This class is used to create plugins that are aware of when items (nested documents) are added or
removed 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 nested
document adding and removing you want to trap. For example, if you want a plugin to be called
whenever an item is added to, or removed from, an invoice, the plugins Table function should return the
ID number of the Invoice table.
Note that the Doc reference received in the Initialize still points to the current document in the selected
table (the document which is having nested documents added or removed). To access the nested
document which is being added or removed use the NestedDocByID or NestedDocByName methods of
the Doc reference.

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 decide
whether to allow it being removed or not.

Return Value

Returning the Boolean value True will allow Retail Pro to remove this item. The value
False 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 decide
whether 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 be
discarded.

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 the
document 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 a
document 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 the
added item is larger than one.

4.5.5 TSideButton
TSideButton = class
class 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 be
added. Currently the following values are possible:
smDepartments
smVendors
smCustomers
smInventory
smReceipts
smReceiptList
smVouchers
smVoucherList
smMemos
smMemoList
smSlip
smSlipList
smSO
smSOList
smPO
smPOList
smTO
smTOList
smTender
Note: for screens where Form view and List view have different menus there are
TSideMenu types for both menus respectively. For example, smRecipts corresponds to
the 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.

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 Pro
calls this function periodically when it is idle so unlike the other properties of the
button (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.

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:
arRefreshDocument
arRefreshList
The return value forces Retail Pro to update the view of the current document or list
to make sure any changes made during the execute method are displayed.
Return arRefreshList if your button is on a list menu, and arRefreshDocument if your
button 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 = class
procedure 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 tender
information 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 when
tendering 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 tender
screen. 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.

4.5.7 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 unlimited
function 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 used
on both regular and nested documents. The value of the field is not stored in the Retail Pro database so
it is up to the plugin itself to save and retrieve values and associate them with the correct document if
necessary.
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 values
are possible:
cftString
cftInteger
cftDouble
cftQuantity
cftCurrency
cftDate
cftTime
cftDateTime

Preconditions

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

Post conditions The return value is a valid TCustomFieldType Value.

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 of
the class has been instantiated. You cannot reference any regular members from this
function.

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 of
time.

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 of
the class has been instantiated. You cannot reference any regular members from this
function.

Post conditions The return value is a valid string.

4.5.7.4 MaxChars Method


MaxChars

function MaxChars: integer; virtual; abstract;

Description

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

Return Value

Return an integer value representing the maximum number of characters. Return zero
to 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.

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 drop
down 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 down
list. 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 custom
field. 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 and
displayed according to the FieldType.

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 value
must 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 not
pass 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 user
entered/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 = class
class 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 event
method 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 the
Document 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 Document
Printer. This information may be modified to produce a customized print out. If
nothing 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 the
document information to be printed.

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

5.0 Creating a Plugin


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

5.1 Create a New Package Project


From Delphis main menu select File->New. From the New Items dialog box, make sure you have the tab
labeled 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 of
the 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;

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 the
Invoices 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 what
classes are available inside the package.
procedure RProClassesAvailable(RProClassArrayProc:
TRProClassArrayProc);
begin
RProClassArrayProc([TInvcUpdate]);
end;

5.1.5 Compile the plugin package


To compile a Delphi package you must click the Compile button on the package manager window rather
than using the Compile command off the main menu.

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

Appendix A Code listing of the Retail Pro API (3/2002)


(For Reference ONLY DO NOT COPY THIS CODE.)
unit RProAPI;
interface
uses
RDA2_TLB;
const
AllFields = -100;
csClassesAvailableName = 'RProClassesAvailable';
type
TRProClassArrayProc = 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 = class
function 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;

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 = class
class 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-consuming
function 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 unlimited
function IsReadOnly: boolean; virtual; abstract;
function GetData: variant; virtual; abstract;
procedure SetData(Value: variant); virtual; abstract;
function LookupList: string; virtual; abstract;
end;
implementation
initialization
end.

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}
requires
vcl50,
RPRO_API;
contains
uInvoiceItemChange;
end.

uInvoiceItemChange.pas
unit uInvoiceItemChange;
interface
uses
RProAPI, RDA2_TLB, Dialogs, SysUtils;
type
TInvcItemNumAssigned = 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

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)
private
public
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;
exports
RProClassesAvailable;
{ 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);
var
IsNull: WordBool;
begin
if 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;
begin
ItemNo := fInvoiceItem.GetInteger(fidItemNo, IsNull);
Result := true;

if ItemNo = 2 then
begin
Result := false;
ShowMessage(Format('Item # %d cannot be removed', [ItemNo]));
end
else
ShowMessage(Format('Item # %d is removed', [ItemNo]));
end;
function TInvcItemAddRemove.ItemBeforeAdd(ItemNo: integer): boolean;
begin
Result := true;
if ItemNo = 3 then
begin
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);
begin
end;
function TInvcItemNumValidate.Validate(var Value: variant): boolean;
begin
Result := true;
case Value of
4:
begin
Result := false;
ShowMessage('Item # 4 rejected');
end;
5:
begin
Value := 6;
ShowMessage('Item # 5 replaced with Item # 6');
end;
end;
end;
end.

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}
requires
vcl50,
RPRO_API;
contains
uPrintInvoice;
end.

uPrintInvoice
unit uPrintInvoice;
interface
uses
Windows, RProAPI, RDA2_TLB, Dialogs, SysUtils, MSXML_TLB, ShellAPI;
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;
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

procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);


begin
RProClassArrayProc([TInvcUpdate]);
end;
exports
RProClassesAvailable;
{ 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 then
begin
Result := false;
ShowMessage('Receipts > $100 are not allowed');
end
else
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.

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}
requires
vcl50,
RPRO_API;
contains
uInvoiceButton;
end.

uInvoiceButton.pas
unit uInvoiceButton;
interface
uses
Windows, RProAPI, RDA2_TLB, SysUtils;
type
TInvoiceButton = class(TSideButton)
Private
fRProApp: TRProApp;
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;
TTenderButton = class(TSideButton)
private

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;
exports
RProClassesAvailable;
{ 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);
begin
fRProApp := RproApp;
fInvoice := Doc;
end;
function TInvoiceButton.Execute: TActionRequestSet;
begin
// \\CORDELIA\RD1
fRProApp.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;

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;
begin
Tender := 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;
begin
ShowMessage(IntToStr(fTender.TenderItems.length));
if fTender.Undefined < 0 then
begin
Item := fTender.AddItem(ttFC);
fc := Item as IRdaFC;
fc.Amount := fTender.Undefined;
fc.FCAmount := 1000;
fc.FCName := 'ROUBLES';
end;
end;
end.

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}
requires
vcl50,
RPRO_API;
contains
uInvoiceField;
end.

uInvoiceField.pas
unit uInvoiceField;
interface
uses
Windows, Classes, RProAPI, RDA2_TLB, Dialogs, SysUtils, MSXML_TLB, ShellAPI;
type
TInvcWrappingKind = class(TCustomField)
private
fInvoice: IRdaDocument;
fData: TStringList;
public
class 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
const
csFileName = 'wrappings.txt';
procedure RProClassesAvailable(RProClassArrayProc: TRProClassArrayProc);
begin
RProClassArrayProc([TInvcWrappingKind]);
end;
exports
RProClassesAvailable;
{ 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);
except
end;
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';

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 customer
end;
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.

Das könnte Ihnen auch gefallen