how to access object field names from strings (opposite of aqObject.GetFields())
My script uses the Storages and FileSection objects in order to persist (write) custom objects to .ini files. There are many different types of objects; I need to write and read the data back into object instances using a generic method. Writing and reading from the files is easy. The problem is converting a string back to a variable name when it represents an object field.
For example, if my script needed an object to store data about cars, the object would be defined like this:
function Car()
{
this.DescId = "CAR";
this.Year = "";
this.Make = "";
this.Model = "";
}
At runtime an instance of a Car would be written to an .ini file, like this:
[CAR]
DescId=CAR
Year=1965
Make=Ford
Model=Mustang
By convention every object has a DescId field which gets leveraged for ini file subsections.
All objects are written to the file using:
var iniFileSection = iniFileHandle.GetSubSection(obj.DescId);
var objFields = aqObject.GetFields(obj);
for (var i = 0; i < objFields.Count; i++)
{
iniFileSection.SetOption(objFields.Item(i).Name, objFields.Item(i).Value);
}
To read the CAR from the file and load back into an object, the field names (DescId, Year, Make, Model) need to be converted from strings back into the variable names they represent.
This:
aqObject.SetPropertyValue(obj, objFields.Item(i).Name, iniFileSection.GetOption(objFields.Item(i).Name, -1));
does not work.
It seems aqObject.Unquote()should work, but what is the syntax to make it an object field? Is there a way to fix this bad syntax:
obj.(aqString.Unquote(objFields.Item(i).Name) = objVal;
Thanks,
Amy