将名称的变量更改为输入(Pascal) [英] change the variable of which the name is given as input (Pascal)
问题描述
我想知道解决这个问题的基本方法。还要特别感兴趣的是Pascal的具体解决方案。
I would like to know if there's a basic way to solve this issue. Also especially interested in specific solutions for Pascal.
让我们说一个有2个输入的表单:'InputVARIABLE'和'InputVALUE'。
Let say we have a form with 2 inputs: 'InputVARIABLE' and 'InputVALUE'.
在InputVARIABLE区域中,用户键入要更改的变量的名称。在InputVALUE区域中,用户键入该变量的值。
In the InputVARIABLE area the user types the name of a variable he want to change. In the InputVALUE area the user types the value of this variable.
因此,对于inputtexts的color和blue:如何在不使用IF语句的情况下更改变量VAR_color像:
So for inputtexts 'color' and 'blue': how can I change the variable VAR_color without using IF statements like:
If InputVARIABLE.Text = 'color' Then VAR_color := InputVALUE.Text;
是否有一些功能,例如:
Is there for instance some function like:
ChangeVariable(InputVARIABLE.Text, InputValue.Text)
希望你可以帮助!
推荐答案
一般来说,您不能使用文本表示中的名称访问Pascal中的符号(string )
In general, you can't access symbols in Pascal using their name in a textual representation (string)
对象Pascal / Delphi有一些扩展,但它们主要是为了特定目的(例如允许框架在不知道的情况下流式传输数据),而较少对于正常的代码。
Object Pascal/Delphi have some extensions for this, but they are mainly meant for specific purposes (by e.g. allowing a framework to stream data without knowing it), and less for normal code.
所以需要改变计划。通常,您可以在一个变量名称的数组中查找名称(如果对象Pascal为tstringlist),并且如果找到有效的匹配,则使用索引将结果设置为数组。
So a change in plan is needed. Usually you look up the names in an array of variablenames (or tstringlist if Object Pascal), and if a valid match is found, then you use the index to set the result in an array.
这篇关于将名称的变量更改为输入(Pascal)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!