这个关于包的程序为什么会报错?(50分)

  • 主题发起人 主题发起人 tulip_88
  • 开始时间 开始时间
T

tulip_88

Unregistered / Unconfirmed
GUEST, unregistred user!

//******** 包 **************//
package testdp1;

{$R *.res}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$DESIGNONLY}
{$IMPLICITBUILD OFF}

requires
rtl,
vcl;

contains
test1 in 'test1.pas' {Form1};

end.

unit test1;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.dfm}

end.

//*************** 调用包的程序 ****************//
program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {MainForm};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.


unit Unit1;

interface

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

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

var
MainForm: TMainForm;

implementation

uses test1;

{$R *.dfm}

procedure TMainForm.Button1Click(Sender: TObject);
begin
Form1.ShowModal;
end;

end.


Button1的OnClick事件会出现"Access voilation at address xxxx in module 'project1.exe '"的错误提示,请教:程序该怎么改才能通过?
 
procedure TMainForm.Button1Click(Sender: TObject);
begin
Form1:=TForm.create(self);
Form1.ShowModal;
end;
 
to xzh2000:
加上 Form1:=TForm.create(self); ,编译时会提示:imcompatible types:'TForm1' and 'TForm'
 
procedure TMainForm.Button1Click(Sender: TObject);
begin
Form1:=TForm1.create(self);
Form1.ShowModal;
end;
 

Similar threads

后退
顶部