AddRule method

The AddRule method adds a document integrity rule to a SetupNode object. For example, you can use this method to add a rule that specifies that a document type must contain a specific page type.

Document integrity rules specify the required structure of the document. For example, a rule for the document type Invoice might specify that documents of this type must have a page of type Main_Page. A rule for the page type Main_Page might specify that pages of this type must have a field of type Invoice_Total.

If a SetupNode object for the specified child object does not exist, this method creates the SetupNode object.

Syntax

VBScript
AddRule(ObjectType as Long, lpszChildName as String, 
   nPosition as Long, MinNumber as Long, MaxNumber as Long) 
   as Boolean
C#
int AddRule(int nObjectType, string lpszChildName, 
   short nPosition, short nMinNumber, short nMaxNumber)

Arguments

nObjectType
Use one of the following number values to determine the object type of the child node:
0 = Batch
1 = Document
2 = Page
3 = Field
lpszChildName
The name of the child object, which is stored as the type attribute of the rule.
nPosition
The position that child objects of this type must be relative to other child items at run time. In the DCO Setup window, this value is the Order property of the child node.
nMinNumber
The minimum number of instances of this child object that must exist for the document structure to be valid.
nMaxNumber
The maximum number of instances of this child object that can exist for the document structure to be valid.

Returns

Returns true if successful; returns false if unsuccessful.

C# example

This example gets the SetupNode object for the Invoice document in the Setup DCO. The example then adds a rule that requires one instance of the page NewPage to exist for the document structure to be valid. If a page node for NewPage does not exist, the method creates NewPage automatically.

m_oDCO.ReadSetup("C:\\Datacap\\APT\\dco_APT\\APT.XML");
TDCOLib.DCOSetup m_oDCOSetup = m_oDCO.SetupObject();
TDCOLib.DCOSetupNode m_oDCOSetupNode = 
   m_oDCOSetup.GetNodeByName(1, "Invoice");
m_oDCOSetupNode.AddRule(2, "NewPage", 0, 1, 1);

The following line is added to the Setup DCO:

	<D type="Invoice">
	.
	.
	.
	<P type="NewPage" pos="0" min="1" max="1"/> <!-- New line added -->

Additionally, if NewPage does not exist, the following page node is created:

<P type="NewPage">
	<V n="ID">0</V>
	<V n="TYPE">Page</V>
	<V n="STATUS">0</V>
	<V n="IMAGEFILE"></V>
	<V n="DATAFILE"></V>
	<V n="TEMPLATE IMAGE"></V>
	<V n="MIN_TYPES">0</V>
	<V n="MAX_TYPES">0</V>
</P>