Resource not found error when using TForm as base for a component

前端 未结 1 1434
星月不相逢
星月不相逢 2020-12-07 03:01

I am writing a component and want to change the base type to a TForm however at run time I get the error \"Resource TMyComp not found\". I guess that this is because there

相关标签:
1条回答
  • 2020-12-07 03:29

    There is no .dfm file for TMyComp. You can avoid attempting to load the .dfm by calling the CreateNew constructor rather than Create.

    Mc := TMyComp.CreateNew(Self);
    

    From the documentation:

    Use CreateNew instead of Create to create a form without using the associated .DFM file to initialize it. Always use CreateNew if the TCustomForm descendant is not a TForm object or a descendant of TForm.

    CreateNew bypasses the streaming in of the previously-associated .DFM file. If the form contains visual components, therefore, you must stream in an external .DFM to bind the visual components with their classes. If the newly created form has an external .DFM file, then you can follow the call to CreateNew with a call to InitInheritedComponent. If you need to create the .dfm file for the new form instance, bracket the call to CreateNew with calls to WriteComponentResFile and ReadComponentResFile.

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