Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    939

    Registry.DoesValueExist()

    Several forum members have asked for this action by analogy with Registry.DoesKeyExist(). Even without this action it is not difficult to write a working code:

    Code:
    sValueData = Registry.GetValue(HKEY_CURRENT_USER, sMyRegKey, "AppDir", true);
    if sValueData == "" then
    	-- what to do when the value does NOT exist
    else
    	-- do something when value does exist
    end
    There is a disadvantage with this code; the setup log will have en "Error" entry. I do not want the end user to believe there is a malfunction in my setup.

    To avoid the log error message, I have to add this test:

    Code:
    nTypeValue = Registry.GetValueType(nFolder, sKey, sValue);
    if nTypeValue == 0 then
    	-- the value does NOT exist
    else
    	-- OK, read the value
    end
    Sometimes I want the data from several values assigned to the same key. Another way to avoid the log error:

    Code:
    sRegAppDir = "?"; sRegUninDate = "0000-00-00"; 	-- init
    sRegInstDate = "0000-00-00"; sRegVer = "?";	-- init
    
    sIrpKey = SessionVar.Expand("Software\\%CompanyName%\\%ProductName%");
    
    tValueNames = Registry.GetValueNames(HKEY_CURRENT_USER, sIrpKey);
    for i, d in tValueNames do
    	if d == "AppDir" then
    		sRegAppDir = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, "AppDir", true);
    	elseif d == "Uninstalled" then
    		sRegUninDate = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, " Uninstalled ", true);
    	elseif d == "Installed" then
    		sRegInstDate = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, " Installed ", true);			
    	elseif d == "Version" then
    		sRegVer = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, "Version", true);			
    	end
    end
    Obviously the test for the existence of a value is a recurring operation. Today I decided to write a generic function and put it in a table like Lorne has taught us (AMS Examples).

    To put functions into tables is a great feature. My collection is increasing!

    If I use the table 'Registry', I can use my function this way:

    bAppDirExist = Registry.DoesValueExist("HKCU", sRegKey, sValueName);

    At last I come to my question:

    Is it dangerous to use a table with the name 'Registry' because that is a group of internal actions in SUF70 (and other IR products)?

    (If you are interested, you will find the function in the attached file.)
    BTW, Moderator, could .lua be an permitted file extension for upload?
    Attached Files

  2. #2
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    939

    IR Team, please!

    I should highly appreciate your answer:

    Is there any disadvantage in using an 'internal table name' when creating a user defined function?

    Example: Registry.DoesValueExist() as in my previous post.

    I'm now going to publish a project with an 'action extension' like that; but I shouldn't if the method is "dangerous".

  3. #3
    Join Date
    Jan 2000
    Posts
    2,002
    There is no real "danger" per-se. The only risk being run is if we ever added that function to the product. Although even then yours would overwrite it so if you like your function, then there is no problem.

    Personally if I were making a library of extended registry functions I would call it something like RegistryEx or RegistryExtended. But either way is fine.

  4. #4
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    939
    Thanks for your time, Brett.

    I'll go for RegistryEx (I liked that suggestion); it is less confusing both at present and in the future.

    BTW, my published function should start with a Registry.DoesKeyExist() action.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts