Forum Discussion

EngoTom's avatar
EngoTom
Visitor
16 years ago

roRegistry

From page 85 of the component reference doc.

Why is the variable reg created? I only see sec being used in the following 2 functions.

Also... When calling this function, what does "return invalid" return? I need to if block the return value...

Finally... When calling SetAuthData() will this example take into account a null registry section or one already populated with data. If null I want to create and save data, if not null I want to overwrite value.

THX...

Function GetAuthData() As Dynamic
reg = CreateObject("roRegistry")
sec = CreateObject("roRegistrySection", "Authentication")
if sec.Exists("UserRegistrationToken")
return sec.Read("UserRegistrationToken")
endif
return invalid
End Function

Function SetAuthData(userToken As String) As Void
reg = CreateObject("roRegistry")
sec = CreateObject("roRegistrySection", "Authentication")
sec.Write("UserRegistrationToken ", userToken)
sec.Flush()
End Function

6 Replies

  • "EngoTom" wrote:
    From page 85 of the component reference doc.

    Why is the variable reg created? I only see sec being used in the following 2 functions.

    Funny. I was wondering the same thing last night. I thought creating the roRegistry object might initialize something somewhere, but I found that removing that line from my code didn't change any behavior, so I'm curious what it's for as well.

    "EngoTom" wrote:
    Also... When calling this function, what does "return invalid" return? I need to if block the return value...

    "invalid" is the null or Nothing of BrightScript, so "return invalid" gives you a return value that you can test for validity (ex. If token = invalid Then prompt user for credentials).

    "EngoTom" wrote:
    Finally... When calling SetAuthData() will this example take into account a null registry section or one already populated with data. If null I want to create and save data, if not null I want to overwrite value.

    This code will create the registry section if it doesn't already exist, or it will overwrite what's already there if it does exist.

    TheEndless
  • OK Thanks for your reply.

    Kevin, Patrick will you enlighten us on the use of reg in your documentation example?

    THX
  • EngoTom,

    You are correct that the roRegistry object is not necessary to read/write from the registry sections. It's methods are only useful to iterate and manage the different sections of the registry.

    Its inclusion in the examples is historical as it used to be the only way to Flush() the registry... but now Flush() can be called on roRegistrySection directly.

    --Kevin
  • "RokuKevin" wrote:
    [roRegistry] inclusion in the examples is historical as it used to be the only way to Flush() the registry... but now Flush() can be called on roRegistrySection directly.

    Is there a difference between using ifRegistrySection.flush() and ifRegistry.flush()?
    E.g. is flushing a section (potentially) faster than the whole registry - or does flushing a section not flush all sections as well?
  • As it's currently implemented, RegistrySection.Flush just calls Registry.Flush, which flushes the whole registry. I wouldn't preclude the possibility that someday RegistrySection.Flush might be changed to only flush that one section, but I don't know of any plans to change it.

    --Mark
  • Thank you RokuMarkn, your answer - concise as always - is appreciated!
    Yeah, i can imagine how registry could be partitioned - yet the 16kb limit will render performance benefits negligible.