The Object Manager provides a convenient way of structuring and handling data as objects with attributes.
Entities of the real world can be modeled as objects with attributes. For example, a person can have the attributes name, age and hobbies. Unforunately, app inventor doesn't provide a convenient way to encapsulate your data representing objects. Data in app inventor is usually structured in form of lists. Handling those lists or lists of lists can often be very confusing and tedious.
The Object Manager enables to define attributes and handle your data in form of objects containing attribute values. Think of the Object Manager as a local and temporal database, where you can store, query and retrieve your entities and their attributes. The attributes are named so you can call them by their name in addition to calling them by their index. Attribute values are not restricted, they can be numbers, text, logicals as well as lists of values. You can use several search methods and select objects or return the attribute values. Consider the Quick Sort extension for sorting objects.
You can create local objects (CreateEmptyObject) and assign attribute values (SetValue). The local representation of an object is a list containing the attributes as items. Before you can start to create objects, you have to define the attribute names (SetAttributeNames) and thus the structure of your objects.
To store objects, you have to add it to the manager (AddObject), which assigns a unique ID to it. Use this ID to retrieve the list representation of the object (GetObject), to update it (SetObject), to get values (GetValueById), to update values (SetValueById) and to delete the object (DeleteObject).
To reference the attributes, you can provide the index as number or the name as text.
The GetIndices method allows to search an object using its list representation. Since duplicate entries are possible, it returns a list of indices instead of a single number.
This group of blocks concerns the whole set of objects. GetObjects returns a list of the list representations, GetIds their IDs. The GetAllValues method returns all the extisting values for a specific attribute, for example a list of all ages.
DeleteAllObjects removes all the objects, ResetObjectManager additionally deletes the definition of the attributes.
To initialize the manager, you have to set the attribute names once (SetAttributeNames).
The SearchObjects blocks return an ID list of all the objects in the manager, which have a specific attribute value. You can choose if the value should be less, equal or greater than the specified value, or if it should contain the value as a substring.
For complex search queries, set operations will be useful. If you want to find all persons who are between 20 and 30 years old, you will need separate queries for the persons > 20 and < 30 years. Then you can use the intersection operation to get the final result. For persons younger than 40 years who don't play football, search (a) for people aged < 40 and (b) people who play football. The Difference (a) minus (b) gives the result.
The following example shows the various possibilities you have with the object manager. Of course, this application would be hardly meaningful, it's just a demonstration of how you can use the different blocks.
(name age hobbies)
(Benny 33 (football cooking))
((Anne 27 basketball) (Benny 33 (football cooking)) (Carmen 42 reading))
(27 33 42)
(Carmen 42 reading)
The price of this extension is 8 EUR (10 USD). If you want to purchase it, you can contact me via the contact form.