Delphi - Create class from a string
问题 I got code like this 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; Is there a way just to do result := $name.create or some way of creating class based of a variable value? All the classes extended the same base class. 回答1: Starting with Delphi 2010, the enhanced RTTI allows you do this without having to creating your own Class Registry. Using the RTTI Unit you have several