Delphi 将TForm用作组件的基础时出现“找不到资源”错误

Delphi 将TForm用作组件的基础时出现“找不到资源”错误,delphi,Delphi,我正在编写一个组件,希望将基类型更改为TForm,但在运行时,我收到错误“Resource TMyComp not found”。我想这是因为没有dfm,但我不知道该怎么办 谢谢 unit Unit65; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.

我正在编写一个组件,希望将基类型更改为TForm,但在运行时,我收到错误“Resource TMyComp not found”。我想这是因为没有dfm,但我不知道该怎么办

谢谢

unit Unit65;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TMyComp = class(TForm);

  TForm65 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    Mc: TMyComp;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form65: TForm65;

implementation

{$R *.dfm}

procedure TForm65.Button1Click(Sender: TObject);
begin
  Mc := TMyComp.Create(Self);
  Mc.Parent := nil;
  Mc.ShowModal;
end;

end.

TMyComp
没有.dfm文件。通过调用构造函数而不是
Create
,可以避免尝试加载.dfm

Mc := TMyComp.CreateNew(Self);
从:

使用CreateNew而不是Create来创建表单,而不使用 关联的.DFM文件来初始化它。如果 TCustomForm子体不是TForm对象或TForm的子体

CreateNew绕过以前关联的.DFM的流式导入 文件因此,如果表单包含可视组件,则必须 流在外部.DFM中,以将可视组件与其 上课。如果新创建的表单具有外部.DFM文件,则 可以在调用CreateNew之后调用 InitInheritedComponent。如果需要为 新建表单实例,将对CreateNew的调用与对 WriteComponentResFile和ReadComponentResFile


您可能想看看Delphi定制容器包