【问题标题】:Issue of roRegistrySection in Roku?Roku 中的 roRegistrySection 问题?
【发布时间】:2019-09-03 22:35:38
【问题描述】:

我尝试创建一个 roRegistration 部分并编写两个函数 GetAuthData 和 SetAuthData 我尝试在 SetAuthData 中传递多个参数并使用 GetAuthData 读取。

Function GetAuthData() As Dynamic
 sec = CreateObject("roRegistrySection", "Authentication")
' print "section : " + Authentication
 if sec.Exists("Authentication")
  print "Read URL : " + m.top.GlobleURL
  print " ****************** DATA :" + m.top.GlobleURL
  return sec.Read("Authentication")
 'return sec.Delete("Authentication") ' Here not override concept so compalsary delete first and after again second URL Store pannel.brs and hud.brs both file

 print "***********************GetAuthData************************"
 endif
 return invalid
End Function

'Here the SetAuthData to wrire URL
Function SetAuthData(Serverurl As String,zxorausername As String, zxorapassword As String) As Void
 sec = CreateObject("roRegistrySection", "Authentication")
 m.top.GlobleURL = Serverurl
 m.top.globalusername = zxorausername       
 m.top.globalpass = zxorapassword
sec.Write("Authentication", m.top.GlobleURL)
sec.Write("Authentication", m.top.globalusername)
sec.write("Authentication", m.top.globalpass)
?"key for the URL" sec.GetKeyList()

    Print "Write URL :" + m.top.GlobleURL
    Print " Write username :" + m.top.globalusername + " Write pass :" + m.top.globalpass

 print "***********************SetAuthData************************"
End Function

我调用 GetAuth 数据如下所示

m.top.GlobleURL = GetAuthData()
m.top.globalusername = GetAuthData()
m.top.globalpass = GetAuthData()

我打印了所有三个项目,但每次都打印 m.top.GlobleURL 值。我试图存储所有三个值。但只存储一个值。有人知道这个问题吗?

编辑后的帖子

Function GetAuthData(key as string) As Dynamic
' reg = CreateObject("roRegistry")
 sec = CreateObject("roRegistrySection", "Authentication")
' print "section : " + Authentication
 if sec.Exists(key)
        return sec.Read(key)
 end if
    return invalid
 'return sec.Delete("Authentication") ' Here not override concept so compalsary delete first and after again second URL Store pannel.brs and hud.brs both file

 print "***********************GetAuthData************************"
End Function

'Here the SetAuthData to wrire URL
Function SetAuthData(Serverurl As String,zxorausername As String, zxorapassword As String) As Void
' reg = CreateObject("roRegistry")
 sec = CreateObject("roRegistrySection", "Authentication")
 m.top.GlobleURL = Serverurl
 m.top.globalusername = zxorausername       
 m.top.globalpass = zxorapassword

' if not m.top.GlobleURL = Serverurl 
    sec.Write("url", m.top.GlobleURL)
    sec.Write("username", m.top.globalusername)
    sec.write("password", m.top.globalpass)
sec.Flush()
?"key for the URL" sec.GetKeyList()
    Print "Write URL :" + m.top.GlobleURL
    Print " Write username :" + m.top.globalusername + " Write pass :" + m.top.globalpass
' end if
 print "***********************SetAuthData************************"
' Flush(true)
End Function

并使用

打印
m.keyUrl = GetAuthData("url")
m.keyUserName = GetAuthData("username")
m.keyPassword = GetAuthData("password")

?"URL Print : "  m.keyUrl
?"Username print : " m.keyUserName
?"password print : " m.keyPassword

【问题讨论】:

    标签: roku brightscript


    【解决方案1】:

    在您的代码中,您正在“Authentication”部分中编写“Authentication”键。而且您正在写入相同的密钥,即它被覆盖。这就是为什么你只有一把钥匙。请使用 write function () as --

    Function SetAuthData(Serverurl As String,zxorausername As String, zxorapassword As String) As Void
        sec = CreateObject("roRegistrySection", "Authentication")
        m.top.GlobleURL = Serverurl
        m.top.globalusername = zxorausername       
        m.top.globalpass = zxorapassword
        sec.Write("url", m.top.GlobleURL)
        sec.Write("username", m.top.globalusername)
        sec.write("password", m.top.globalpass)
        sec.Flush()         // add this to code
        print"key for the URL" sec.GetKeyList()
    End Function
    

    使 get 函数通用以访问多个键--

    Function GetAuthData( key as String) As Dynamic
    sec = CreateObject("roRegistrySection", "Authentication")
        if sec.Exists(key)
            return sec.Read(key)
        endif
        return invalid
    End Function
    

    现在您可以访问密钥了--

    keyUrl = GetAuthData("url")
    keyUserName = GetAuthData("username")
    keyPassword = GetAuthData("password")
    

    希望这会有所帮助。

    (注意:-您可以使用“ReadMulti”方法一次读取多个键。但是个人建议不要使用它,因为它会涉及创建和读取 AssociativeArrays,并会产生不必要的复杂性。)

    【讨论】:

    • 感谢您的回复。这里直接获取key属性?
    • 是的,如果不指定密钥,您将如何访问该值。以及注册表如何知道您要读取哪个键。
    • 抱歉,我的输出无效
    • 确保正确写入键值。
    • 谢谢,对不起。它现在正在工作。这是我的流程中的一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多