0
votes

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
1
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 whithout knowing exact reason. "WTO = oayoay_whichtransobject(dw_pb_report)" gets proper return value from the function.Shoki
For future reference it is always a good idea to mention the version of PB you are using.Matt Balent
PowerBuilder v11.5 on Windows 7 64bit. The function is a global function. I am not sure if a window function name when starting with underscore will result in empty string of hard coded string return value. Please find out that yourself. @Matt Balent Thanks for reminding me about versions.Shoki
I am sorry i forgot to mention that above global function is example of poor coding. You can see RptAt is not set inside the loop (yes crazy). In fact loop will not work when you go deeper into nested reports to look for blob columns. for that purpose a recursive function call is better idea. I mean if there is a nested report in the DW object and that nested report further have nested reports and so on. That case need recursive call. I have to update this function but for now i just hope to have it done by someone else like @Matt Balent with Bundle of Thanks in advance. cheers!Shoki
Generally good practice to answer the question yourself (if you solved it) and mark as correct answer this way should others look they will see it's been answered. This question probably won't be referenced again- but developers will look at it to help you then later learn it has been answered. Welcome to SO.Rich Bianco

1 Answers

0
votes

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.