我的 PowerBuilder 函数在某些条件下返回硬编码字符串值。
我检查了调试器,其中一个条件肯定会发回硬编码字符串,但在调用函数的一侧,我总是得到空字符串“”。
这个 PowerBuilder 技巧对我来说是新的,我无法弄清楚是该函数有问题还是调用该函数的脚本有问题。
请查看该函数的代码并帮助我摆脱这些 PowerBuilder 的困境。 :(
问候,
/// 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
/// 以下是调用上面函数的代码
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
重命名函数解决了这个问题。
对于我总是以下划线开头的事件来说,这从来不是问题。但是,我在不知道确切原因的情况下猜测更改了函数名称。
WTO = oayoay_whichtransobject(dw_pb_report)
从函数中获取正确的返回值。这是一个全球性的功能。