本文介绍了使用TForm作为组件的基础时找不到资源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个组件,并希望将基本类型更改为TForm,但在运行时我收到错误Resource TMyComp not found。我想这是因为没有dfm,但我不知道该怎么做。谢谢
接口
使用
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;
{私人声明}
public
{公开声明}
end;
var
Form65:TForm65;
执行
{$ R * .dfm}
程序TForm65.Button1Click(发件人:TObject);
begin
Mc:= TMyComp.Create(Self);
Mc.Parent:= nil;
Mc.ShowModal;
结束
结束。
解决方案
没有.dfm文件为 TMyComp
。您可以通过调用构造函数,而不是创建
。
Mc:= TMyComp.CreateNew(Self);
从:
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 is no dfm but I am not sure what to do about it.
Thanks
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.
解决方案
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:
这篇关于使用TForm作为组件的基础时找不到资源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!