如何设置默认值以在Delphi中记录 [英] How to set default value to record in delphi
本文介绍了如何设置默认值以在Delphi中记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用RAD XE7。在我的Delphi应用程序中,我想为Records的字段设置默认值。
I am using RAD XE7. In my Delphi application I want to set default values for fields of Records.
我尝试下面的代码,但是它不能编译,我知道这是错误的。还有其他方法吗?
I tried following code, but it does not compile, I know it is wrong. I there any another way?
TDtcData = record
TableFormat : TExtTableFormat = fmNoExtendedData;
DTC : integer = 0;
Description : string = 'Dummy';
Status : TDtcStatus;
OccurenceCnt : integer =20;
FirstDTCSnapShot: integer;
LastDTCSnapShot: integer;
end;
推荐答案
如果要定义部分初始化的记录,只需声明常量记录,但忽略不需要默认值的那些参数:
If you want to define a partially initialized record, just declare a constant record, but omit those parameters not needing default values:
Type
TDtcData = record
TableFormat : TExtTableFormat;
DTC : integer;
Description : string;
Status : TDtcStatus;
OccurenceCnt : integer;
FirstDTCSnapShot: integer;
LastDTCSnapShot: integer;
end;
Const
cDefaultDtcData : TDtcData =
(TableFormat : fmNoExtendedData;
DTC : 0;
Description : 'Dummy';
OccurenceCnt : 20);
var
someDtcData : TDtcData;
begin
...
someDtcData := cDefaultDtcData;
...
end;
这篇关于如何设置默认值以在Delphi中记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文