Search code examples
functionreturnpowerbuilder

Why the return value is always a blank string?


My PowerBuilder function returns hard coded string values on certain conditions.

I checked in debugger and one of the condition surely send back the hard coded string but on the side where call was made to the function, i always get empty string "".

This PowerBuilder trick is new for me and i could not figure out if that function is problem or the the script that calls the function.

Please see the code of the function and help me out of these PowerBuilder ditches. :(

Regards,

/// Function Name: _wichTransObject
/// Parameters: Gets Datawindow control
/// Return: String name of the transaction object to use.
/// Purpose: when image is there in nested reports or the directly blob column is used in datawindow object,
/// only native connection can display images while ODBC fails. This function was written to select proper 
/// transaction object so images are displayed in reports.

String dwSyntax, dwo, OriginalDwo
Long RptAt, RptDwoAt, BlobAt

dw_1.SetRedraw(FALSE)
OriginalDwo = dw_1.DataObject

dwSyntax = dw_1.Describe("datawindow.syntax");

/// Nested Reports may have images in them. That can be checked 
/// find the report and if exist then pick its dwo and repeat same steps again for more reports
RptAt = Pos(dwSyntax, "report(", 1)
DO WHILE RptAt > 0
    RptDwoAt = 0
    RptDwoAt = Pos(dwSyntax, "dataobject=", RptAt) /// Get the dataobject of current report
    IF RptDwoAt > 0 THEN
        /// set the dataobject to dw_1 and explore it further
        dwo = Mid(dwSyntax, RptDwoAt + 12, Pos(dwSyntax, "~"", RptDwoAt + 12)  - ( RptDwoAt + 12 ))
        dw_1.DataObject = dwo

        /// explore the nested dataobject and look for blob column
        dwSyntax = dw_1.Describe("datawindow.syntax");
        BlobAt = Pos(dwSyntax, "keyclause", 1) 
        IF BlobAt > 0 THEN /// if blob exist then return NATCA
            dw_1.DataObject = OriginalDwo
            dw_1.SetRedraw(TRUE)
            Return "NATCA"
        END IF
    END IF
LOOP

/// find the report and if exist then pick its dwo and repeat same steps again for more reports
BlobAt = Pos(dwSyntax, "keyclause", 1)
IF BlobAt > 0 THEN
    dw_1.DataObject = OriginalDwo
    dw_1.SetRedraw(TRUE)
    Return "NATCA"
ELSE
    dw_1.DataObject = OriginalDwo
    dw_1.SetRedraw(TRUE)
    Return "SQLCA"  
END IF

/// Following is the code that gives call to the function above

String WTO

WTO = _WhichTransObject(dw_pb_report)
IF WTO = "NATCA" THEN
    /// Make a native connection
    dw_1.SetTransObject(NATCA)
ELSE
    /// Go away with ODBC
    dw_1.SetTransObject(SQLCA)
END IF

Solution

  • Renaming the function solved this problem.

    This was never a problem with events that i always start with underscore. But, i made a guess to change function name without knowing exact reason.

    WTO = oayoay_whichtransobject(dw_pb_report) gets proper return value from the function. That was a global function.