SetProp

PowerBuilder Native Interface

IPB_Session interface:

SetProp method

Description

Adds a new variable to the list of properties of the current session or changes the value of an existing variable.

Syntax

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 value resides

Return Values

None.

Examples

In this example, the native class has two functions. This is their description passed in the PBX_GetDescription function:

"subroutine f_setprop(int a)\n"
"function int f_getprop()\n"

The functions are associated with these enumerated values:

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:

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:

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.

This set of functions is particularly useful for working with multiple threads of execution in EAServer.

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