本文介绍了无法在Delphi 7中创建动态表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这段代码汇总在一起以创建动态表单

I have put together this code for creating a dynamic form

unit Unit1;

 interface

 uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

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


  type
    TForm2 = class(TForm)
     private
       { Private declarations }
    public
      { Public declarations }
    end;

  var
    Form2: TForm2;
    Form1: TForm1;

implementation

  {$R *.dfm}

  procedure TForm1.Button1Click(Sender: TObject);
 var
     a:TForm2;
 begin
     a:=TForm2.Create(nil);
   end;

end。

我遇到错误说找不到资源tform2。我该怎么办?

I get an error saying resource tform2 cannot be found. What must i do?

谢谢

推荐答案

TForm.Create()构造函数,该构造函数从DFM加载TForm内容,但是您的项目没有用于TForm2的DFM,这就是为什么出现资源错误的原因。要跳过这一点,您需要使用 TForm.CreateNew()构造函数。

You are calling the TForm.Create() constructor that loads the TForm contents from a DFM, but your project does not have a DFM for TForm2, which is why you are getting the resource error. To skip that, you need to use the TForm.CreateNew() constructor instead.

procedure TForm1.Button1Click(Sender: TObject);
var
  a: TForm2;
begin
  a := TForm2.CreateNew(nil, 0);
  ...
end;

这篇关于无法在Delphi 7中创建动态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 05:56