
Adobe Acrobat SDK
Working with Cos Objects
Developing Plug-ins and Applications
Retrieving Cos array values 185
3. Create a
CosObj
object that stores a value to add to the Cos array. For example, to create a
CosObj
object that is based on an integer value, invoke the
CosNewInteger
method and pass the following
arguments:
●
A
CosDoc
object.
●
An
ASBool
object that specifies whether the
CosObj
object is an indirect or direct object. If
true
,
the string is an indirect object. If
false
, the string is a direct object. For information, see
“About
direct and indirect objects” on page 179
.
●
An
ASInt32
value that specifies the integer value.
4. Add the value to the Cos array by invoking the
CosArrayPut
method and passing the following
arguments:
●
A
CosObj
object that represents a Cos array.
●
An
ASTArraySize
object that specifies a 0-based index value.
●
A
CosObj
object that stores the value to add to the array.
The following code example creates a Cos array and adds the values
1
,
2
,
3
,
4
, and
5
to it. A
PDDoc
object
named
myPDDoc
is passed to the
PDDocGetCosDoc
method. For information, see
“Creating a PDDoc
object” on page 83
.
Example 17.3
Creating a Cos array
//Create a new Cos array
CosObj ArrayObj, IntObj;
CosDoc cd = PDDocGetCosDoc(myPDDoc);
ArrayObj = CosNewArray (cd, false, 5);
for (int i=1; i<=5; i++)
{
//Create a new CosObj representing the integer value
IntObj = CosNewInteger (cd, false, i);
//Store the integer object in the array
CosArrayPut (ArrayObj, i-1, IntObj);
}
Retrieving Cos array values
You can retrieve values from a Cos array by performing the following tasks:
1. Determine the number of elements by invoking the
CosArrayLength
method. Pass the
CosObj
object that represents the Cos array as an argument.
2. Get the
CosObj
object that represents an array element by invoking the
CosArrayGet
method and
passing the following arguments:
●
The
CosObj
object that represents the Cos array
●
An
ASTArraySize
object that represents the index of the array element to retrieve
The
CosArrayGet
method returns a
CosObj
object that represents the element
3. Get the element value. However, you must invoke the method that corresponds to the
CosObj
object’s
data type. If, for example, the Cos array stores integer values, invoke the
CosIntegerValue
method
to obtain the element’s integer value. Pass the
CosObj
object that represents the element. This
method returns the corresponding value. If the
CosIntegerValue
method is invoked, then an
ASInt32
value is returned.