Examples – PB Docs 125
Examples The following code fragments are from a C++ program that opens a window. The window has a menu item that invokes the Open event of a PowerBuilder application. Calling ProcessPBMessage The call to ProcessPBMessage is in a loop in the WinMain function:
1 |
int __stdcall WinMain(HINSTANCE hInstance, <br>                      HINSTANCE hPrevInstance,<br>                      LPSTR lpCmdLine,<br>                      int nCmdShow)<br>{<br>   MSG msg;<br> <br>   WNDCLASSEX wcex;<br> <br>// initialization code omitted<br>   ...<br>   RegisterClassEx(&wcex);<br> <br>   HWND hWnd = CreateWindow(szWndClsName,<br>      "OpenPBWindow", WS_OVERLAPPEDWINDOW,<br>      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL,<br>      hInstance, NULL);<br> <br>   if (!hWnd)<br>   {<br>    return FALSE;<br>   }<br> <br>   ShowWindow(hWnd, nCmdShow);<br>   UpdateWindow(hWnd);<br> <br>   try<br>   {<br>       while (GetMessage(&msg, NULL, 0, 0)) <br>       {<br>          TranslateMessage(&msg);<br>          DispatchMessage(&msg);<br> <br>          // Call to ProcessPBMessage<br>          if (session)<br>             session-><span>ProcessPBMessage</span>();<br>      }<br>   }<br>   catch(...)<br>      {<br>          MessageBox(NULL, "Exception occurs",<br>            "Exception", MB_OK);<br>      }<br>   return msg.wParam;<br>} |
Loading the PBVM and triggering an event In the WndProc function,…
GetArray – PB Docs 125
PBBoundedArrayCreator template class: GetArray method Description Obtains an array that has been created. Syntax
1 |
GetArray() |
Return Values pbarray. Examples This example sets up an array, reads in values, and then obtains the values in the array:
1 |
LPCTSTR *ostr_a;<br>char **sp;<br>int i;<br>pbarray out_array;<br>arrayBounds* bounds;<br>pbuint dim1, dim2, current_dim;<br>pblong itemcount1, itemcount2;<br>PBXRESULT ret;<br>PBArrayInfo* ai;<br>pbstring *iarg, *oarg;<br>typedef PBBoundedArrayCreator<pbvalue_string><br>   BoundedStringArrayCreator;<br> |
1 |
in >> dim1;<br>// allocate memory for pointer bounds <br>bounds = (arrayBounds*)malloc(dim1*sizeof<br>   (PBArrayInfo::ArrayBound));<br>bounds = new arrayBounds[dim1];<br>// read in lowerbound and upperbound for each dimension<br>// and calculate the array item count<br>itemcount1 = 1;<br>for (i=0;i<dim1;i++)<br>{<br>  in >> bounds[i].lowerBound >> bounds[i].upperBound; <br>  itemcount1 = itemcount1*<br>    (bounds[i].upperBound - bounds[i].lowerBound +1);<br>}<br>sp = new char*[itemcount1];<br>ostr_a = new LPCTSTR[itemcount1];<br>iarg = new pbstring[itemcount1];<br>// Read in array items<br>for (i=0; i<itemcount1; i++)<br>{<br>  sp[i] = new char[20];<br>  in >> sp[i]; <br>  iarg[i]= session->NewString(sp[i]);<br>}<br>// create bounded simple array and set iarg[i] to it<br>{<br>  BoundedStringArrayCreator ac(session, dim1, bounds);<br>  current_dim = 1;<br>  BoundedArrayItem<pbstring, pbvalue_string,<br>       BoundedStringArrayCreator>::f_set_arrayitem<br>       (session, ac, dim1, bounds, iarg, current_dim);<br>  BoundedArrayItem<pbstring, pbvalue_string,<br>      BoundedStringArrayCreator>::array_itemcount = 0;<br>  out_array = ac.<span>GetArray</span>();<br>} |
See Also SetAt Document get from Powerbuilder help Thank you for watching.
SetAt – PB Docs 125
PBArrayAccessor template class: SetAt method Description Sets the array item at the specified dimension. Syntax For arrays of a specified ValueType:
1 |
SetAt(pblong <span>dim</span>[ ], ValueType <span>v</span>) |
For string arrays:
1 |
SetAt(pblong <span>dim</span>[ ], LPCTSTR <span>string</span><span></span>) |
1 |
SetAt(pblong <span>dim</span>[ ], pbstring <span>string</span><span></span>) |
Argument Description dim The dimension of the array item to be set v A ValueType defined in pbtraits.h string A string of type pbstring or LPCTSTR Return Values None….
SetToNull – PB Docs 125
IPB_Value interface: SetToNull method Description Sets the data contained in the IPB_Value instance to null so the data can be reset. Syntax
1 |
SetToNull( ) |
Return Values PBXRESULT. If the value is a read-only argument, the error PBX_E_READONLY_ARGS is returned. Examples This example shows the use of SetToNull when a null blob value is returned:
1 |
case pbvalue_blob:<br>   pStr=(LPCTSTR)Session-> GetBlob(retVal.blob_val); <br>   if (strncmp(pStr, "null", 4)==0 )<br>      ci->returnValue-><span>SetToNull</span>();<br>   else<br>      ci->returnValue->SetBlob(retVal.blob_val);<br>    break;<br>... |
See…
IPB_Value interface – PB Docs 125
IPB_Value interface IPB_Value has three sets of methods: helper methods, set methods, and get methods. Helper methods The IPB_Value interface helper methods provide access to information about variables and arguments, including the value’s class and type, whether it is an array or simple type, whether it is set by reference, and whether the null flag…
GetAt – PB Docs 125
PBObjectArrayAccessor class: GetAt method Description Obtains the array item at the specified dimension. Syntax
1 |
GetAt(pblong <span>dim</span>[]) |
Return Values pbobject. Argument Description dim The dimension of the array item to be set Examples This example shows the use of GetAt in an object array:
1 |
PBObjectArrayAccessor aa(session, *array_val);<br>for (i=0;i<itemcount2;i++)<br>{<br>   dim[0] = i+1;<br>   oarg = aa.<span>GetAt</span>(dim);<br>   cls = session->GetClass(oarg);<br>   if( cls == NULL ) <br>     return;<br>   fid = session->GetFieldID(cls, "text");<br>   if ( fid == 0xffff) <br>     return;<br>   fid_pv = session->GetFieldAddress(oarg,fid);<br>   mystr = fid_pv->GetString();<br>   ostr_a[i] = session->GetString(mystr);<br>} |
See Also SetAt Document get from Powerbuilder help Thank you for watching.
IPB_Arguments interface – PB Docs 125
IPB_Arguments interface The IPB_Arguments interface has two methods: GetCount obtains the number of arguments in a method call. GetAt obtains the value at a specific index of the pArgs member of the PBCallInfo structure. For each argument, GetAt returns a pointer to the IPB_Value interface. The following code fragment uses GetCount and GetAt in a…
PBCallInfo structure – PB Docs 125
PBCallInfo structure The PBCallInfo structure is used to hold data and return type information for calls between extensions and the PBVM. It has three public members:
1 |
IPB_Arguments*   pArgs;<br>IPB_Value*           returnValue;<br>pbclass                   returnClass; |
The following code initializes a PBCallInfo structure using the IPB_Session InitCallInfo method. After allocating a PBCallInfo structure called ci, the IPB_Session GetClass and GetMethodID methods are used to…
Step 5: Export methods to create class instances – PB Docs 125
Step 5: Export methods to create class instances PowerBuilder creates nonvisual and visual class instances differently: For visual classes, the instance is created when the window or visual control in which the class is used is opened. See “Creating visual class instances”. For nonvisual classes, the instance is created when the PowerBuilder CREATE statement is…
Step 1: Decide on a feature to implement – PB Docs 125
Step 1: Decide on a feature to implement The first step in building a PowerBuilder extension is to identify a problem that an extension can solve. This might be a feature that can be coded more efficiently and easily in C++ than in PowerScript, or that requires the use of callback functions or nonstandard datatypes….