StrataFrame Forum

RegistryRepository GetValue not working

http://forum.strataframe.net/Topic8372.aspx

By Andria Jensen - 4/20/2007

I have been using the RegistryRepository for a while now, and today came across an interesting bug.  I'm not sure if it just hasn't presented itself until now or if it was introduced recently.  When I do a GetValue and send in a DefaultValue it is not returning the DefaultValue if the value is missing from the registry.  It is always returning a False if the value is not there, and in the case of this bug it should be returning a True.  Any idea what is going on here?
By Trent L. Taylor - 4/20/2007

I cannot reproduce this behavior you are describing and we use it everywhere.  Can you provide a sample that will replicate the behavior?
By Andria Jensen - 4/20/2007

Okay, here's a little sample.  When you enter in a default value it should show up as that value when you click 'Get Value' since the value should be missing from the registry.  It works as it should for Int and String values.  But for the Boolean, it always returns False whether it is checked or not.  Maybe I'm doing something wrong in the code, in which case you could correct me.  Please let me know what you think.  Thanks for the help.
By StrataFrame Team - 4/23/2007

Aha, I stepped through the sample and figured it out.  The ReadValue() method of the registry repository isn't meant to be called externally; it's supposed to be private, not public.  If the ReadValue() method cannot retrieve the value, the ByRef parameter is set to Nothing, and when you set a value type to Nothing, it defaults to the "default" value for that value type.  All of the ReadXX() methods like ReadString(), ReadInt32(), etc. all call the read value internally.  They test the return value of the ReadValue() and return the default value if passed directly.  The reason there is no read Boolean is that there is no Boolean data type in the Windows registry.  You have to use an integer and test for > 0 or use a string and parse the "true" or "false" from the string.  I'll add an enhancement request to add a ReadBoolean that stores values in a WORD registry type and uses 0 for False and 1 for True.  In the meantime, you can add your own ReadBoolean or just test on the return value of the ReadValue() method; it will tell you whether the value was successfully retrieved from the database.
By Andria Jensen - 4/23/2007

Ok, that makes total sense.  We can just use a string or an int value and convert to bool.  Thanks for the help.