界面设计和输出结果如下
代码如下:
unit Unit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Forms,
Dialogs,StdCtrls
type Tmyrecord=record //定义用户的数据类型(记录类型)①
a:string;
b:string;
c:integer;
end;
type
TForm1=class(TForm)
Edit1:TEdit;
Edit2:TEdit;
Edit3:TEdit;
Button1:TButton;
procedure Button1Click(Sender:TObject);
private
{Private declarations}
function f:Tmyrecord; //定义函数②
public
{Public declarations}
end;
var
Form1:TForm1;
re1:Tmyrecord; //声明变量记录③
implementation
{$R*.dfm}
{TForm1}
function TForm1.f:Tmyrecord;
begin //给记录变量赋值(对记录变量操作)④
re1.a:='string';
re1.b:='string2';
re1.c:=128;
end;
procedure TForm1.Button11Click(Sender:TObject);
begin
f; //调用函数
edit1.Text:=re1.a;
edit1.Text:=re1.b;
edit1.Text:=IntToStr(re1.c);
end;
end.
几点说明 :
1. ①必须在②前,否则出错,这是因为要先定义数据类型在引用类型。
2.声明记录变量在Var部分,是先声明记录变量,然后再对记录变量赋值(或其他操作)。
3.完成了③,在④部分操作时,当输入“记录变量名.”后,系统经自动提示记录,如re1中的abc