Totally Objects - Registry - Version 5.5 [1.0]

Introduction

This document explains how to use the Registry product from Totally Objects for IBM's VisualAge for Smalltalk. The product has been designed to help you to use the Registry in your Windows 95/98/ME/NT/2000 applications. It enables you to do simple tasks such as read and write strings and integers in an area especially for you application, read and write Smalltalk objects or access registry items related to other applications, users or the system.

This application enables you to treat any Node (or Key as they are known in Microsoft speak) in the registry as a dictionary. This means you can simply use methods such as #at:put: and #at: to store and retrieve your data. A full list of methods is given later.

Installing Registry

This Totally Objects product has been packaged as a single application. To import it into your library select 'Browse Application Editions' from the 'Tools' menu of the 'System Transcript'. In the 'Application Editions Browser' select 'Import...' from the 'Names' menu and select the file registry5-5_1-0-*.dat. You should then select RegistryApp, Version 5.5 [1.0.*] contained within this file.

To load the application into your image select it in the 'Application Editions Browser' select 'Load' from the 'Editions' menu. Note that this application does not require any of the VisualAge Parts applications to be loaded into your image.

Simple Example Storing and retrieving data for your application

If you wish to use the registry to store and retrieve data relating to your application then you first need to create the appropriate node in the registry. This is done as follows:

To access this node for storing and retrieving data you should do the following:

To add items to this node you should use #at:put: such as:

The only objects that can be entered into the registry in this way are Strings, Arrays or Strings, ByteArrays or Integers (positive and less than 4294967296). The first argument of #at:put: must always be a String.

If you take a look in the registry using regedit.exe and open up the hierarchical list to view 'HKEY_LOCAL_MACHINE\SOFTWARE\My Company\My Application\1.0' you should see the items there.

The default item for any node has the key '' (an empty String).

To retrieve any of these items use #at:ifAbsentOrError:. For example:

The value of the block is answered if the node does not exist, if there is no item with the given name or an error occurs (possibly due to unauthorized access to the registry).

To store Smalltalk objects other than those mentioned above you need to use the methods #at:putObject: and #objectAt:. The object is converted to and from ByteArrays before storing and retrieving it by using the swapper. For example, to store a Point:

to retrieve it:

As well as storing data relating to a particular version of an application, you can also store data relating to the current user of the system and a particular application. To do this use the RegistryNode class methods #currentUserRegisterCompany:software:version: and #currentUserCompany:software:version: for creating and accessing the data instead of #registerCompany:software:version: and #company:software:version:.

Advanced Operations

Sometimes you will wish to store and retrieve data in the registry that cannot be accessed using the methods in the simple example above. In these cases you will need to specify the path of the node in which you are interested when creating your RegistryNode object. The class methods of RegistryNode in the category 'Top Level Nodes' enable you to do this. For example, if you want to specify the node with the path 'HKEY_CURRENT_USER\Control Panel\Colors' you would do the following:

Items can be stored and retrieved as in the simple example.

Instance Methods of RegistryNode

This section explains what each of the public instance methods of the class RegistryNode does. Whenever the explanation reads 'As Dictionary' this means that the method will behave as in the class Dictionary except for the following caveats:

Method

Description

=

Answers true if the receiver and the argument refer to the same node in the registry, otherwise answers false.

add:

As Dictionary.

addAll:

As Dictionary.

addAllNodesCalled:

The argument must be a Collection of Strings. New nodes are added to the registry beneath the node referenced by receiver. The names of the new nodes are the strings in the Collection.

addNodeCalled:

Adds a node to the registry beneath the node referenced by the receiver. The name of this new node is given by the argument.

associationAt:ifAbsent:

As Dictionary.

associationsDo:

As Dictionary.

at:

As Dictionary. The object answered will be a String, an Array of Strings, a ByteArray or an Integer.

at:ifAbsent:

As Dictionary. The object answered will be a String, an Array of Strings, a ByteArray or an Integer.

at:ifAbsentOrError:

As #at:ifAbsent: but also answers the value of the exception block if an error occurs.

at:ifAbsentPut:

As Dictionary.

at:ifPresent:

As Dictionary.

at:put:

As Dictionary. The second argument must be a String, an Array of Strings, a ByteArray or an Integer (positive and less than 4294967296 i.e. an unsigned 32bit integer). If you wish to store Integers outside this range then either convert them to Strings (using #printStringRadix:showRadix:) or store them using #at:putObject:

at:putBigEndianUint32:

Stores an Integer in BigEndian format.

at:putObject:

Converts the second argument into a ByteArray using the Swapper and puts it into the registry. Normal Swapper restrictions and guidelines apply.

collect:

As Dictionary. This answers a Dictionary.

do:

As Dictionary.

exists

Answers true if the node actually exists in the registry, otherwise it answers false. Note that just because a node exists does not mean that you have authority to add items to it.

hasSubNodes

Answers true if this node has nodes beneath it in the registry, otherwise it answers false.

includes:

As Dictionary.

includesKey:

As Dictionary.

isEmpty

As Dictionary.

keyAtValue:ifAbsent:

As Dictionary.

keys

As Dictionary.

keysAndValuesDo:

As Dictionary.

keysDo:

As Dictionary.

notEmpty

As Dictionary.

objectAt:

Retrieves the ByteArray stored in the registry and converts it into a Smalltalk object using the Swapper.

objectAt:ifAbsentOrError:

The same as #objectAt: but answers the value of the block (the second argument) if the item does not exist or an error occurs.

partialName

Answers the name of the node without the preceding path.

reject:

As Dictionary.

removeAllKeys:

As Dictionary.

removeAllKeys:ifAbsent:

As Dictionary.

removeKey:ifAbsent:

As Dictionary.

removeKey:ifAbsentOrError:

The same as #removeKey:ifAbsent: but answers the value of the block (the second argument) if the item if an error occurs.

removeNodeCalled:ifAbsentOrError:

Removes the sub-node with the name given by the first argument. It answers the name if the node is deleted successfully but answers the value of the block (the second argument) if an error occurs.

select:

As Dictionary.

size

As Dictionary.

sortedSubNodes

The same as #subNodes but answers an OrderedCollection sorted alphabetically on the partial name of the node.

subNodeName:

Answers a new RegistryNode referencing the sub-node of the receiver with a name specified in the argument.

subNodes

Answers a Set of RegistryNodes that reference the sub-nodes of the node referenced by the receiver.

subNodesDo:

Iteratively evaluates a one argument block (the argument) using each of the RegistryNodes answered by #subNodes.

subNodesNames

Answers a Set of the names of the sub-nodes of the receiver.


Further Information