GetPBAnyField
Description
Obtains the value of a variable of type Any.
Syntax
|
1 |
GetPBAnyField( pbobject obj, pbfieldID fid, pbboolean& isNull ) |
|
Argument |
Description |
|---|---|
|
obj |
A valid object handle for the object whose value is |
|
fid |
The field ID of the variable |
|
isNull |
Indicates whether the variable is |
Return value
IPB_Value*.
Examples
This example tests all the functions used to get the value of
variables of type Any, using PushLocalFrame and PopLocalFrame to
simulate the scope of a function call:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
session->PushLocalFrame(); pbgroup vgroup = session->FindGroup("n_test", pbgroup_userobject); pbclass vcls = session->FindClass(vgroup, "n_test"); pbobject vobj = session->NewObject(vcls); pbboolean isNull; pbfieldID vfid = session->GetFieldID(vcls, "i_a"); IPB_Value* value = session->GetPBAnyField(vobj, vfid, isNull); pbstring str = value->GetString(); // save actual value vfid = session->GetSharedVarID(vgroup, "s_a"); value = session->GetPBAnySharedVar(vgroup, vfid, isNull); //Get the actual value here. vfid = session->GetGlobalVarID("g_a"); value = session->GetPBAnyGlobalVar(vfid, isNull); //Get the actual value here. vfid = session->GetFieldID(vcls, "i_array"); pbarray arr = session->GetArrayField(vobj, vfid, isNull); //Get the any array first. long dim = 1; value = session->GetPBAnyArrayItem(arr, &dim, isNull); //Get the actual value here. session->PopLocalFrame(); |
Usage
The value you retrieve must be of datatype Any to use this
function; that is, the variable associated with the function must be
declared as a variable of type Any in the development environment. If it
is not, the function returns a null pointer and the value of isNull is
set to true.
This function returns a pointer to an IPB_Value instance. When it
is called, memory is allocated for the returned IPB_Value instance, and
the pointer is recorded in the current local frame. The pointer is
deleted automatically when the current local frame is popped, which
occurs when the current local function returns (you can also call
PopLocalFrame to force the frame to be popped).
If you want to use the value returned, you must save the value
pointed to by the IPB_Value instance (not the IPB_Value instance itself)
before the frame is popped. If you save the pointer itself, the value is
only valid until the original value is destroyed.
You can use the AcquireValue function to save the value, or one of
the IPB_Value Get<type> functions. For example, the following code
saves the string value in the IPB_Value instance ivalue into the string
str. The value in str can be used after the local frame is popped and
ivalue is deleted:
|
1 2 3 |
IPB_Value* ivalue = session->GetPBAnyField(vobj, vfid, isNull); pbstring str = ivalue->GetString(); |
If you do not know the actual datatype of the Any variable, use
the IPB_Value GetType function to get its datatype first, then use the
appropriate get function to get its value.
IPB_Value holds a reference to the original value
The value in the IPB_Value instance is a reference to the
original value. If you change the actual value of the returned
IPB_Value, the original value is also changed. If you use the
AcquireValue function to save the value, it clones a new IPB_Value and
resets the existing IPB_Value pointer.
See also