RTTI:我可以通过名称获取类型吗?(RTTI: Can I Get a Type by Name?)
给定一个包含类型名称的文本字符串,是否有某种方法可以获得适当的类型本身?
我期待着做这样的事情:
type TSomeType<T> = class // yadda yadda end; procedure DoSomething; var obj : TObject; begin o := TSomeType<GetTypeByName('integer')>.Create; // do stuff with obj end;
我在网上查看了几个RTTI解释,并查看了德尔福单元,但没有看到我在找什么。 这可能吗?
Given a text string containing a type name, is there some way to get the appropriate type itself?
I'm looking to do something like this:
type TSomeType<T> = class // yadda yadda end; procedure DoSomething; var obj : TObject; begin o := TSomeType<GetTypeByName('integer')>.Create; // do stuff with obj end;
I've looked at several RTTI explanations online and looked through the Delphi units and don't see what I'm looking for. Is this possible?
原文:https://stackoverflow.com/questions/1668645
最满意答案
事实证明,错误来自于对列表框和文本框使用相同的ID。 在UiApp中,一次只显示一个,但是首先生成任何问题类型,例如文本框,当下面生成的问题是列表框时,错误就会出现,反之亦然。 如果生成的所有问题都是相同的用户输入,则错误永远不会发生(例如,如果所有问题都通过列表框收集用户输入)。 启动分数问题功能时,我需要两者的ID相同。 我想跟进的问题是如何从应用程序中删除最后一个输入类型的残余,以便错误停止发生? 我试过通过getElementById删除用户输入,但它似乎不起作用。
It turns out the error is coming from using the same id for a listbox and textbox. In the UiApp there is only one showing up at a time but whatever question type is generated first, say a textbox, the error comes when a question generated following is a listbox or visa versa. If all questions generated will be the same user input the error never happens (like if all questions gather user input through a listbox). I need the id to be the same for both for when the score question function is launched. I guess a follow up question would be how do I remove the remnants of the last input type from the app so the error stops happening? I've tried removing the user input by getElementById and it doesn't seem to work.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
parseFloat仅在其第一个参数中接受字符串。 那是错误。 由于你已经有了一个数字,你不需要在上面调用praseFloat 。 只需括在括号中并在结果上调用.toFixed(1) 。 unitDateValue = (differenceBetweenDates / (1000 * 60 * 60 * 24)).toFixed(0); parseFloat only accepts strings in its first parameter. That's the error. Since you' ...
-
要从参数中删除引号,可以使用语法%~1 。 在批处理文件中它看起来像 @echo off myProg.exe %~1 To remove quotes from a parameter, you can use the syntax %~1. In a batch file it looks like @echo off myProg.exe %~1
-
事实证明,错误来自于对列表框和文本框使用相同的ID。 在UiApp中,一次只显示一个,但是首先生成任何问题类型,例如文本框,当下面生成的问题是列表框时,错误就会出现,反之亦然。 如果生成的所有问题都是相同的用户输入,则错误永远不会发生(例如,如果所有问题都通过列表框收集用户输入)。 启动分数问题功能时,我需要两者的ID相同。 我想跟进的问题是如何从应用程序中删除最后一个输入类型的残余,以便错误停止发生? 我试过通过getElementById删除用户输入,但它似乎不起作用。 It turns out the ...
-
您正在检查返回值是字符串的实例,例如"hello" 。 但是你的方法返回类String ,即String.class 。 我想你的方法会返回你想要的东西。 在这种情况下,您甚至没有使用hamecrest进行验证。 常规JUnit的Assert.assertEquals(String.class, result.getType())将适合您。 You are checking that the return value is instance of string, e.g. "hello". But your ...
-
参数未通过(Parameter not passed through well)[2024-03-22]
如果在参数值中有perl特殊字符,则将参数嵌入perl脚本可能会导致问题。 最好做点什么 crypt_pass() { echo $(perl -e 'print crypt($ARGV[0], "aa")' "$1") } Embedding the parameter inside a perl script can lead to trouble if there are characters special to perl in the parameter value. Best to d ... -
问题是宏实现中U的弱类型标记的参数基本上是符号T ,而不是Int 。 以下内容将起作用(请注意,为了清晰起见,我缩短了一些名称并替换了已弃用的方法): import scala.language.experimental.macros import scala.reflect.macros.Context object Macros { def applyImpl[ T: c.WeakTypeTag, U: c.WeakTypeTag ](c: Context)(e: c.Expr ...
-
作为文字传递的字符变量的默认长度是32.我的猜测是JCHKSTS期望一个32字节的变量。 尝试DCL &ENVPORT *CHAR 32 The default length for a character variable passed as a literal is 32. My guess is that JCHKSTS is expecting a 32 byte variable. Try DCL &ENVPORT *CHAR 32
-
您试图传递调用_fmincg_evaluate函数的结果,而不是传递实际的_fmincg_evaluate函数。 你要: fmincg(_fmincg_evaluate, inputFeatures->matrix, inputFeatures.elementCount, 50); fmincg的实现将负责调用传入的函数指针及其所需的任何参数。 更新:正如Adrian在下面的评论中所指出的,由于参数类型不匹配,因此无法将_fmincg_evaluate函数作为_fmincg_evaluate函数的第一个参 ...