找不到文件“ Form2.dcu”

时间:2018-11-15 20:36:24

标签: delphi delphi-7

我无法解决此问题,有人可以帮助吗?

第1单元代码:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Form2; //error here

type
  TForm1 = class(TForm)

这是第2单元

unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    CESTITAMO: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Rezultat11: TLabel;
    REZULTAT21: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

end.

是的,我创建的Form2的标题为“ Cestitke!”。并保留名称为Form2

我想知道将来如何解决它,谢谢

3 个答案:

答案 0 :(得分:7)

我认为您误解了错误。

您的用途是

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Form2; //error here

但是要访问Form2,需要在列表中包括的不是不是表单的名称,而是声明表单所在单位的名称,即Unit2

因此,您的“用途”列表应显示为:

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

但是通常在这种情况下,在Unit1的实现部分的Unit2列表中包含Uses就足够了。

答案 1 :(得分:3)

没有任何单位Form2.pas。在您的uses子句中用Unit2替换Form2。

答案 2 :(得分:2)

从用途中删除“ Form2”,并添加“ uses Unit2;”。到实施部分。这是一个有效的示例:

unit Unit1;

interface

{uses //Delphi 10.2
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;}

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;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.ShowModal; //or Form2.Show;
end;

end.