delphi 中record如何定义以及调用?

先定义了一个记录TOwnBook=recordCode:string;Name:string;Price:string;OwnDays:integer;end;然后在后面... 先定义了一个记录TOwnBook = record
Code : string;
Name : string;
Price : string;
OwnDays : integer;
end;
然后在后面又定义了一个变量tempOwnBook为TOwnBook类型。
结果提示 constant or type identifier expected
代码如下:
unit Unit4;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, DB, ADODB, Mask, ExtCtrls;

type
TForm4 = class(TForm)

GroupBox1: TGroupBox;
Panel1: TPanel;
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
StaticText6: TStaticText;
StaticText7: TStaticText;
ComboBox1: TComboBox;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBMemo1: TDBMemo;
StaticText8: TStaticText;
StaticText9: TStaticText;
StaticText10: TStaticText;
StaticText11: TStaticText;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ADOTable1: TADOTable;
ADOQuery3: TADOQuery;
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;

var
Form4: TForm4;
TOwnBook : record //定义在此处 是不是因为定义的位置不对?
Code : string;
Name : string;
Price : string;
OwnDays : integer;
end;
....
procedure TForm4.Button1Click(Sender: TObject);
var
tempOwnBook:TOwnBook; //变量定义在此处
begin
...
end.

希望懂的朋友帮忙改正一下 本人QQ263534219 如果能+QQ交流可追加财富悬赏 感激不尽
展开
 我来答
zyjying520
推荐于2018-04-13 · TA获得超过225个赞
知道小有建树答主
回答量:436
采纳率:100%
帮助的人:370万
展开全部
TOwnBook : record 前缺少关键字type以及TownBook与record之间是=号不是:号

应该这样
type
TownBook = record
Code : string;
Name : string;
Price : string;
OwnDays : integer;
end;
位置可以放在这里,不过按照书写代码的风格建议放到
var
Form4: TForm4;这两句的上面,这样一来比较划分区域,代码也显得好看些

调用没有错,就只是那一句错了.
unit Unit4;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, DB, ADODB, Mask, ExtCtrls;

type
TForm4 = class(TForm)

GroupBox1: TGroupBox;
Panel1: TPanel;
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
StaticText6: TStaticText;
StaticText7: TStaticText;
ComboBox1: TComboBox;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBMemo1: TDBMemo;
StaticText8: TStaticText;
StaticText9: TStaticText;
StaticText10: TStaticText;
StaticText11: TStaticText;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ADOTable1: TADOTable;
ADOQuery3: TADOQuery;
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;
type
TOwnBook = record //定义在此处 是不是因为定义的位置不对?
Code : string;
Name : string;
Price : string;
OwnDays : integer;
end;

var
Form4: TForm4;

procedure TForm4.Button1Click(Sender: TObject);
var
tempOwnBook:TOwnBook; //变量定义在此处
begin
...
end.
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式