Although there are other possible ways to address the problem If the intention is to add more elements to the enumerated type seems just a design flaw and is making use of the wrong type.
If you have not yet defined the number of items and you'll be adding more and more, it is clear that go on your design is counterproductive.
It is better to redirect this design to one based on classes as I mentioned in a previous post.
You design The class TMineralList with methods to add and remove items in an internal list. And until it can be designed to do set operations such as union and intersection if you want.
TMineralList assumes responsibility for store / read the file and materialization. If you insist to make the correspondence by string, you be can avail the name of the class. Something like this:
Code:
type
TBlockTypeClass = class of TBlockType; //TBlockType is the abstract base class
var
BlockType: TBlockType;
BlockTypeClass: TBlockTypeClass;
...
Index := BlockLists.IndexOf(TheTextReadFromFile);
BlockTypeClass := TBlockType(BlockLists.Object[Index]);
BlockType := BlockTypeClass.Create;
BlockLists is a TStringList.
To "register" each subclass of TBlockType:
Code:
BlockLists.AddObject(ConcreteBlockType.ClassName, TObject(ConcreteBlockType));
Naturally this design not is "the solution", because it involves add new classes, but when trying to be adding elements to an enumerated type in the first thing you should think about is a lack of design and/or are not using the right path.
I say this with all respect.
Regards,
P.S: Soory for my bad English.
Bookmarks