Although PowerScript is essentially a compiled language, it is quite tolerant. For the sake of performance, the PowerBuilder .NET compiler is not designed to be as tolerant as the PowerBuilder native compiler.
To be able to compile your applications with .NET, you should avoid certain practices in your PowerScript code.
if b = 0 then label: … else … end if goto label
if (b == 0) { // opening a new scope label: … } else { … } goto label;
Since a GoTo statement is not allowed to jump to a label within a different scope in .NET, the C# code would not compile. For this reason, avoid using GoTo statements.
call w1::clicked
base.clicked();
In this example, a possible workaround is to move code from the Clicked event of the indirect ancestor window to a window function, and then call the function, rather than the original Clicked event, from the descendant window.
Event type integer ue_update(int e)
The subclasses of the w_main class should not change the parameters or the return type of the event.
The PowerBuilder compiler does not prevent you from changing the access modifier of a function in an inherited class from protected or private to public, but if you attempt to deploy a .NET target that contains such a function, you receive an error indicating that a private or protected function cannot be accessed.
If your code includes such statements, the compiler returns the error "Return statement cannot be used in finally clause."
Subroutine CopyMemory(ref structure s, int size) library "abc.dll"
The s parameter can accept any datatype that is a pointer to something.
LogInfo li
CopyMemory(ref li, 20) // error!To solve this problem, you can declare an additional external function as follows:
Subroutine CopyMemory(ref LogInfo li, int size) library "abc.dll"
Function boolean SystemTimeToFileTime(os_systemtime lpSystemTime, ref os_filedatetime lpFileTime) library "KERNEL32.DLL"
Function boolean SystemTimeToFileTime(ref os_systemtime lpSystemTime, ref os_filedatetime lpFileTime) library "KERNEL32.DLL"
The SystemTimeToFileTime function is declared as a local external function and used in pfc_n_cst_filesrvunicode, pfc_n_cst_filesrvwin32, and other operating-system-specific classes in the pfcapsrv.pbl in the PFC library. If you use this library in a .NET Windows Forms or Web Forms application, you must change the declaration as described above.
This is not the case in the .NET environment. If the string passed to an external function by reference is empty, and if the external function writes something to the string, an exception is thrown. Therefore, you must make sure to allocate enough space for a string before passing it to an external function by reference.
If the code looks like this:
char* WINAPI fnReturnEnStrA() { return "ANSI String"; }
it is recommended that you alter it like this:
#include <objbase.h> ... ... char* WINAPI fnReturnEnStrA() { char* s = (char*)CoTaskMemAlloc(12); memcpy(s, "ANSI string\0", 12); return s; }