我在TForm中定义了一个类,但是调用就出错,好奇怪
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
filerecord=class
procedure keep(var line1,color1,count1:integer);
procedure Create();
private
public
color,line,count:integer
end;
var
Form1: TForm1;
a:filerecord;
implementation
procedure filerecord.Create();
begin
line:=0;
count:=0;
color:=0;
end;
procedure filerecord.keep(var line1,color1,count1:integer);
begin
line:=line1;
count:=count1;
color:=color1;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
a.Create();
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
begin
a + filerecord.Create();
end;
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
filerecord=class
procedure keep(var line1,color1,count1:integer);
constructor Create();//*********
private
public
color,line,count:integer
end;
var
Form1: TForm1;
a:filerecord;
implementation
constructor filerecord.Create();//**********
begin
line:=0;
count:=0;
color:=0;
end;
procedure filerecord.keep(var line1,color1,count1:integer);
begin
line:=line1;
count:=count1;
color:=color1;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
a:=filerecord.Create();//*********
end;
end.
//带*号是应该改的
同意楼上的。
a := filerecord.Create(); // Object Pascal格式
a.Free; // 也是Object Pascal格式
我来迟了,补充一下吧.你只是定义了一个类,使用的时候需要创建实例,楼上几位仁兄的方法正是如此.