初学者。按照书上的说法试着声明变量,用type语句如下:
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;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
type
Tcolor=(red,blue);
var
c: Tcolor ;
c:=red;
end;
end.
怎么系统总是报错 Project1.dpr(5): Could not compile used unit 'Unit1.pas'?
或者你也可以简单的告诉我。type和var怎么用(我按照书上说的做不行)
delphi 中声明类型变量type放在什么地方?
答案:3 悬赏:0 手机版
解决时间 2021-01-24 22:15
- 提问者网友:轮囘Li巡影
- 2021-01-24 08:50
最佳答案
- 五星知识达人网友:轻熟杀无赦
- 2021-01-24 09:18
type 是定义类型
VAR是声明变量
这两个关键字除了不能放在类定义,过程或函数体内外,基乎可以在任何地方,所放地方的不同,那么他们起的作用域不同.
1.类定义,像如
type //告诉编译器,下面的代码定义一个类
Tform1 = class(Tform) //Tform1 从TForm 继承
....//这里是类的一些属性,函数等等
end; //从Tform1 = class(Tform) 到这个end为止即为一个类定义. 在这中间不允许有 type 和 var出现
2.过程或函数体内部
procedure xxxxxxxxxxxxxxxx; //告诉编译器,下面的代码定义一个过程
begin
...............
end;
function XXXXXXXXXXXXXXX;//告诉编译器,下面的代码定义一个函数
begin
...............
end;//上面的两个begin..end 不允许有 type 和 var出现
VAR是声明变量
这两个关键字除了不能放在类定义,过程或函数体内外,基乎可以在任何地方,所放地方的不同,那么他们起的作用域不同.
1.类定义,像如
type //告诉编译器,下面的代码定义一个类
Tform1 = class(Tform) //Tform1 从TForm 继承
....//这里是类的一些属性,函数等等
end; //从Tform1 = class(Tform) 到这个end为止即为一个类定义. 在这中间不允许有 type 和 var出现
2.过程或函数体内部
procedure xxxxxxxxxxxxxxxx; //告诉编译器,下面的代码定义一个过程
begin
...............
end;
function XXXXXXXXXXXXXXX;//告诉编译器,下面的代码定义一个函数
begin
...............
end;//上面的两个begin..end 不允许有 type 和 var出现
全部回答
- 1楼网友:青尢
- 2021-01-24 11:34
type 是定义类型
var是声明变量
这两个关键字除了不能放在类定义,过程或函数体内外,基乎可以在任何地方,所放地方的不同,那么他们起的作用域不同.
1.类定义,像如
type //告诉编译器,下面的代码定义一个类
tform1 = class(tform) //tform1 从tform 继承
....//这里是类的一些属性,函数等等
end; //从tform1 = class(tform) 到这个end为止即为一个类定义. 在这中间不允许有 type 和 var出现
2.过程或函数体内部
procedure xxxxxxxxxxxxxxxx; //告诉编译器,下面的代码定义一个过程
begin
...............
end;
function xxxxxxxxxxxxxxx;//告诉编译器,下面的代码定义一个函数
begin
...............
end;//上面的两个begin..end 不允许有 type 和 var出现
另外,团idc网上有许多产品团购,便宜有口碑
- 2楼网友:夜风逐马
- 2021-01-24 10:31
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;
Tcolor=(red,blue);
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
c: Tcolor ;
begin
c:=red;
end;
end.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯