This is the string variable that I have:
question1 := 'Please enter 1, 2 or 3.';
I also have a function which is supposed to print out the question1 variable, but it generates the question number before printing. Here’s a fragment of the function, which turns the question number (question : integer) into a string variable (test : string) and then concatenates the string ‘question’ with this string variable (test : string).
str(question,test);
test := concat('question',test);
writeln(test);
The result of this writeln is ‘question1’ (without the quotes). I want it to output the question1 variable as a text string, not just this variable’s name, so that the writeln prints Please enter 1, 2 or 3. I’ve tried writeln(question1) and it works, however, it appears that my function above (or the fragment of it) does this: writeln('question1'). How do I solve this?
Pascal doesn’t support dynamic name resolution, like you want. You might consider using arrays instead: