分享此页面

# 示例: 存储上次输入的值

此示例显示如何使用 TDConnection 对象实现操作之间数据的持久性。例程中变量生存期仅限于例程运行时间。因此, 如果以后要用它, 必须存储持久的数据。建议您尽可能用 ALM API 存储持久数据, 而不使用外部对象、文件或注册表。

在此示例中, 用户发布缺陷时, 用户定义的函数 `SW_KeepLastValue` 使用 Settings 对象保存输入到字段 BG_DETECTION_VERSION`、`BG_USER_01`` 和 BG_USER_03 中的值。此用户添加新缺陷时, 将检索这些值并分配为默认值。

用户发布新缺陷之前, 用 `SET` 操作从 `Bug_CanPost` 调用用户定义的函数。字段中的值已存储。

    Function Bug_CanPost()
            ' Initialize the function's return value to
    	 ' avoid unpredictable behavior.
            Bug_CanPost = True
            If Bug_Fields("BG_BUG_ID").Value = "" Then
                SW_KeepLastValue ("SET")
            End If
    End Function

用 `GET` 操作从 `Bug_New` 事件过程调用该函数。用户添加新缺陷时, 在此用户的字段中存储的值将输入到这些字段中。

    Sub Bug_New()
            SW_KeepLastValue ("GET")
    End Sub

根据作为参数传递的操作, 用户定义的函数 `SW_KeepLastValue` 在当前用户的常用设置表中存储字段的值, 或从 Settings 对象读取值并将值分配到相应字段。

    Sub SW_KeepLastValue(action)
    Dim tdc, vals, flds
    Dim uset, pairs, pair
    Dim bld
    On Error Resume Next
            bld = ""
            Set tdc = TDConnection
            Set uset = tdc.UserSettings
            If action = "SET" Then
                flds = Array("BG_DETECTION_VERSION", _
                "BG_USER_01", "BG_USER_03")
                vals = ""
                For i = 0 To UBound(flds)
                    If vals <> "" Then vals = vals & ";"
                    vals = vals & flds(i) & "=" & _
    		 Bug_Fields(flds(i)).Value
                Next
                'Open category KeepLValueSetting
                uset.Open ("KeepLValueSetting")
                'Setting KeepValueFields in category KeepLValueSetting
                uset.Value("KeepValueFields") = vals
                uset.Close
            End If 'SET
            If action = "GET" Then
                uset.Open ("KeepLValueSetting")
                vals = uset.Value("KeepValueFields")
                If vals <> "" Then
                    pairs = Split(vals, ";")
                    For i = 0 To UBound(pairs)
                        pair = Split(pairs(i), "=")
                        If UBound(pair) = 1 Then
                            Select Case pair(0)
                                Case "BG_USER_03"
                                    bld = pair(1)
                                Case Else
                                    If Bug_Fields(pair(0)).Value = "" Then
                                       Bug_Fields(pair(0)).Value = pair(1)
    				 End If
                            End Select
                            If Bug_Fields("BG_DETECTION_VERSION").Value _
    			 <> ""
                            And bld <> "" Then
                                SW_SetLists_VersionsBuilds _
                                "BG_DETECTION_VERSION", _
                                "BG_USER_03"
                                Bug_Fields("BG_USER_03").Value = bld
                                If Err.Number <> 0 Then Err.Clear
                            End If 'Bug_Fields
                        End If 'UBound(pair)
                    Next
                End If 'vals <> ""
            End If 'GET
            uset.Close
            PrintError ("Keep Last Value (" & action & ")")
            On Error GoTo 0
    End Sub

https://admhelp.microfocus.com ALM 8942
改进搜索结果的提示... ALM 帮助中心 ALM 帮助中心 ALM 帮助 16.00 全部查看本地帮助中心查看联机帮助中心后退在浏览器历史记录中后退前进在浏览器历史记录中前进删除突出显示的搜索项下一个主题转到下一个主题上一个主题转到上一个主题打印当前主题版本: