如何初始化静态数组? [英] How to initialize a static array?

查看:226
本文介绍了如何初始化静态数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个声明:

  TYPE 
RDisk =打包记录
R2:数组字节的[1..1024]
etc
etc
end;

如何使用常量声明将R2初始化为零:

  CONST 
磁盘:RDisk =

R:??
);

这与记录中的记录(无法初始化)

解决方案

省略字段你想要零:

 键入
RDisk =打包记录
R2:array [1..512 ]的字节
I:整数;
D:双
R3:Array [1..512] of Byte;
结束

const
磁盘:RDisk =

I:3;
D:2.5;
);

 code> const 
磁盘:RDisk =

);


我不知道为什么它工作,它不太适合<一个href =http://docwiki.embarcadero.com/RADStudio/en/Declared_Constants#Record_Constants =nofollow>记录常数文档。


Let's say I have this declaration:

TYPE
 RDisk= packed record
   R2: array[1..1024] of Byte;
   etc
   etc
  end;

How do I initialize R2 to zero using a constant declaration like this:

CONST
 Disk: RDisk= 
   (
    R: ??
   );

This is related to Record in record (Cannot initialize)

解决方案

Omit the fields you want to zero:

type
 RDisk= packed record
   R2: array[1..512] of Byte;
   I: Integer;
   D: Double;
   R3: array[1..512] of Byte;
  end;

const
 Disk: RDisk=
   (
    I: 3;
    D: 2.5;
   );

or,

const
 Disk: RDisk=
   (
   );


I don't know why it works, it doesn't quite fit in Record Constants' documentation.

这篇关于如何初始化静态数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆