Class Reference as Property

前端 未结 2 996
囚心锁ツ
囚心锁ツ 2021-02-04 17:51

Google is useless for these sorts of searches, because you get hundreds of millions of results absolutely none of which relate to the specific question.

The question is

相关标签:
2条回答
  • 2021-02-04 18:30

    If you were going to do this then you would need to provide a property editor. The IDE does not come with property editors for class type properties. You would also need to handle .dfm persistence. You would write the class type out to the .dfm file as a string and when the .dfm file is read, you would need to fixup the reference. New style RTTI could do that.

    However, I don't think any of this is actually viable for the following reason. Your design time code runs in a package inside the IDE and does not have access to the class types in the active project in the IDE. Those class types only exist when that project runs. So the ObjectType property in the code in your question cannot be assigned to anything meaningful in the design time package. Well, you could use it for classes defined in the VCL and any other packages installed in your IDE but I rather imagine you'd want to use it on classes defined in the active project.

    I think all this means that you should instead use a simple string property and fixup the class type references only at runtime.

    0 讨论(0)
  • 2021-02-04 18:47

    You can find all classes that descend from a particular base class: Delphi: At runtime find classes that descend from a given base class? and make this a special property with list of values using TPropertyEditor.

    0 讨论(0)
提交回复
热议问题