记录类型的使用

界面设计和输出结果如下

代码如下:

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

 

转载于:https://www.cnblogs.com/chenJazz/p/5711394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值