Home > Enterprise >  Is it possible to declare a TObjectDictionary that has an array of TStringList as the value?
Is it possible to declare a TObjectDictionary that has an array of TStringList as the value?

Time:09-17

I have a task where I need to create a specialized editor for a JSON file that contains the following structure:

{
    "intents": [
        {
            "tag": <string_name>,
            "patterns": [
                <string>,
                <string>,
                <string>...
            ],
            "responses": [
                <string>,
                <string>,
                <string>...
            ],
            <repeats arbitrarily]
        }
    ]
}

The Form has a drop down and two TMemos. The idea is to use the drop down to edit the patterns and responses for each tag. When done, I save back out to the JSON file.

What I am struggling with is how best to store this data in memory to make it easy to switch from one tag to another. I was thinking a TObjectDictionary with the tag name as the key and the values as either the patterns or responses for each one, but then I realized I have to instantiate x number of TObjectDictionarys dynamically, one for each tag.

Is it possible to have a dynamic array with a string field and two TStringList objects instead? I am using TJsonTextReader to walk through the items in the JSON file, and that works fine. I just need some ideas on the best structure to store the data.

CodePudding user response:

You can use a record and put whatever you want in it. Then create an array of record instances. Or store record instances as your dictionary values. Etc.

  • Related