【发布时间】:2011-04-24 19:38:40
【问题描述】:
我得到了这样的代码
name := 'Foo';
If name = 'Foo' then
result := TFoo.Create
else if name = 'Bar' then
result := TBar.Create
else if name = 'FooFoo' then
result := TFooFoo.Create;
有什么办法吗
result := $name.create
或基于变量值创建类的某种方式?
所有类都扩展了同一个基类。
【问题讨论】:
-
谢谢马特,你打败了我
-
你使用的是哪个版本的Delphi?
-
重复:Is there a way to instantiate a class by its name in delphi? 没有近距离投票,因为该问题是在 Delphi 增强 RTTI 之前提出的。
-
OP 似乎很困惑。代码示例显示“按名称创建类的实例”,但问题标题显示“从字符串创建类”,这是一个不同且可能没有用的东西。