SetProp
Description
Adds a new variable to the list of properties of the current
session or changes the value of an existing variable.
Syntax
|
1 |
SetProp(LPCTSTR name, void* data) |
|
Argument |
Description |
|---|---|
|
name |
The name of the property to be set |
|
data |
A pointer to the data buffer where the variable’s |
Return value
None.
Examples
In this example, the native class has two functions. This is their
description passed in the PBX_GetDescription function:
|
1 2 3 4 |
"subroutine f_setprop(int a) " "function int f_getprop() " |
The functions are associated with these enumerated values:
|
1 2 3 4 5 |
enum MethodIDs { mid_SetProp = 0, mid_GetProp = 1 }; |
When the f_setprop function is called from PowerBuilder, the
following code sets the value of the pointer SetVal to the integer value
passed in by f_setprop, then registers that value in the session with
the property name prop_name:
|
1 2 3 4 5 6 7 |
int* SetVal = new int; if (mid == mid_SetProp) { *SetValue = ci -> pArgs -> GetAt(0) -> GetInt(); session -> SetProp(prop_name, SetVal); } |
When the f_getprop function is called, the following code uses
GetProp to set the GetValue pointer to point to the value associated
with prop_name, and then sets the return value to *GetValue:
|
1 2 3 4 5 6 |
if (mid == mid_GetProp) { int* GetVal; GetValue = (int *)session -> GetProp(prop_name); ci -> returnValue -> SetInt(*GetVal); } |
Usage
SetProp enables you to use a variable value throughout an IPB
session without using a global variable, which is susceptible to
namespace conflicts with other sessions. SetProp is one of a set of
three functions:
-
Use SetProp to register a new variable with the session or to
change the value of an existing variable. -
Use GetProp to access the variable.
-
Use RemoveProp to remove the variable from the list of
variables associated with the session when it is no longer
needed.
Suppose you want to throw an exception from within a PBNI
extension and the exception itself is also defined by the PBNI
extension. You call the IPB_Session NewObject function to create an
instance of the exception, causing the PBX_CreateNonVisualObject
function to be called.
One way to set the value of the fields of the exception before the
function returns in a thread-safe manner is to create a new object or
structure to hold the exception information before calling NewObject.
You can call SetProp to store the structure or the object in the current
IPB_Session. When PBX_CreateNonVisualObject is called, you can call
GetProp to get the structure or object to obtain the exception
information, then call RemoveProp to remove the data you stored in the
current session.
See also