This answer shows that you can create a constant generic array of strings. So this code works:
const AllTestJSON: TArray<String> = [
'''
[
{'Computer Webcam', TAlphaColors.Aliceblue},
{'Computer Monitor', TAlphaColors.Blueviolet},
{'Computer Mouse', TAlphaColors.Aqua},
{'Computer Keyboard', TAlphaColors.Blue},
]
''',
'''
[
{'External Harddrive', TAlphaColors.Brown},
{'USB Hub', TAlphaColors.Chartreuse},
{'Computer Mousepad', TAlphaColors.Crimson}
]
''',
'''
[
{'Computer Mouse', TAlphaColors.Aqua},
{'Computer Keyboard', TAlphaColors.Blue},
{'External Harddrive', TAlphaColors.Brown},
]
'''
];
But I don't want a normal array of strings. I want an array of strings with constants like this:
const Test1: String = '''
[
{'Computer Webcam', TAlphaColors.Aliceblue},
{'Computer Monitor', TAlphaColors.Blueviolet},
{'Computer Mouse', TAlphaColors.Aqua},
{'Computer Keyboard', TAlphaColors.Blue},
]
''';
const Test2: String = '''
[
{'External Harddrive', TAlphaColors.Brown},
{'USB Hub', TAlphaColors.Chartreuse},
{'Computer Mousepad', TAlphaColors.Crimson}
]
''';
const Test3: String = '''
[
{'Computer Mouse', TAlphaColors.Aqua},
{'Computer Keyboard', TAlphaColors.Blue},
{'External Harddrive', TAlphaColors.Brown},
]
''';
const AllTestJSON: TArray<String> = [Test1, Test2, Test3];
That however doesn't work and results in the error:
Constant expression expected
Is there a way to do what I am trying to do? I want my strings to be in constants and then put those constants into my array constant.
constyou don't have a variable - the whole point of a variable is that its content is variable (whereas a constant's content is constant). Nothing in your code is (a) variable.