SetString

PowerBuilder Native Interface

IPB_Session interface:

SetString method

Description

Frees an existing string and assigns a new string value to it by performing a deep copy.

Syntax

SetString (pbstring string, LPCTSTR src)

Argument

Description

string

A valid pbstring variable whose value is to be replaced

src

The string to be assigned to string

Return Values

PBXRESULT. Returns PBX_OK for success or PBX_E_INVALID_ARGUMENT if the new string value is invalid; otherwise, returns PBX_E_OUTOF_MEMORY.

Examples

This example uses the IPB_Session SetString method to set the ret_val string to the return value in the PBCallInfo structure. It also uses the IPB_Value SetPBString method to set values in PBCallInfo:

pbclass cls;
pbmethodID mid;
PBCallInfo* ci = new PBCallInfo;
pbstring ret_val;
LPCTSTR pStr;

cls= Session -> GetClass(myobj);
if (isAny)
   mid=Session-> GetMethodID(cls, "uf_any_byvalue",
      PBRT_FUNCTION, "AAAAA");
else
   mid=Session-> GetMethodID(cls, "uf_string_byvalue",
      PBRT_FUNCTION, "SSSSS");
Session-> InitCallInfo(cls, mid, ci);

ci-> pArgs -> GetAt(0) -> SetPBString(s_low);
ci-> pArgs -> GetAt(1) -> SetPBString(s_mid);
ci-> pArgs -> GetAt(2) -> SetPBString(s_high);
pStr = Session -> GetString(s_null);
if (pStr != 0)
{
   if (strcmp(pStr, "null") == 0 )
      ci-> pArgs -> GetAt(3) -> SetToNull();
   else
      ci-> pArgs -> GetAt(3) -> SetPBString(s_null);
}
Session -> InvokeObjectFunction(myobj, mid, ci);
ret_val = Session -> NewString("");
Session -> SetPBString(ret_val, Session->GetString
               (ci->returnValue->GetString()));
Session -> FreeCallInfo(ci);
delete ci;
return ret_val;

Usage

A deep copy is performed. The existing value is destroyed first, and then the contents of the src argument are copied into a new value.

See Also