我对TRecord的使用有疑问。
我可以在记录属性中使用VAR吗?
例如:
我的记录:
TStyleEvalue = record
ID: Integer;
Value: TFontStyles;
Name: String;
end;
当我尝试在属性中将VARName
属性设置为以下代码时:
StylesEvalueArray : array[0..15] of TStyleEvalue = (
(ID: 00; Value: []; Name: LB_NORMAL),
(ID: 01; Value: [fsBold]; Name: LB_NEGRITO),
(ID: 02; Value: [fsItalic]; Name: LB_ITALICO),
(ID: 03; Value: [fsBold,fsItalic]; Name: LB_NEGRITO+', '+LB_ITALICO),
(ID: 04; Value: [fsUnderline]; Name: LB_SUBLINHADO),
(ID: 05; Value: [fsBold,fsUnderline]; Name: LB_NEGRITO+', '+LB_SUBLINHADO),
(ID: 06; Value: [fsItalic,fsUnderline]; Name: LB_ITALICO+', '+LB_SUBLINHADO),
(ID: 07; Value: [fsBold,fsItalic,fsUnderline]; Name: LB_NEGRITO+', '+LB_ITALICO+', '+LB_SUBLINHADO),
(ID: 08; Value: [fsStrikeOut]; Name: LB_TACHADO),
(ID: 09; Value: [fsBold,fsStrikeOut]; Name: LB_NEGRITO+', '+LB_TACHADO),
(ID: 10; Value: [fsItalic,fsStrikeOut]; Name: LB_ITALICO+', '+LB_TACHADO),
(ID: 11; Value: [fsBold,fsItalic,fsStrikeOut]; Name: LB_NEGRITO+', '+LB_ITALICO+', '+LB_TACHADO),
(ID: 12; Value: [fsUnderline,fsStrikeOut]; Name: LB_SUBLINHADO+', '+LB_TACHADO),
(ID: 13; Value: [fsBold,fsUnderline,fsStrikeOut]; Name: LB_NEGRITO+', '+LB_SUBLINHADO+', '+LB_TACHADO),
(ID: 14; Value: [fsItalic,fsUnderline,fsStrikeOut]; Name: LB_ITALICO+', '+LB_SUBLINHADO+', '+LB_TACHADO),
(ID: 15; Value: [fsBold,fsItalic,fsUnderline,fsStrikeOut]; Name: LB_NEGRITO+', '+LB_ITALICO+', '+LB_SUBLINHADO+', '+LB_TACHADO)
);
我收到此错误消息:
[错误] FormFontChange.pas(102):预期的常量表达式
此数组的所有行都会发生此错误。
谁能帮我?
提前致谢。
您正在声明类型常量。用于类型化常量的值必须是称为常量表达式的值。可在以下位置找到该文档:http : //docwiki.embarcadero.com/RADStudio/en/Declared_Constants#Typed_Constants
对于此处的示例,相关部分是覆盖记录常量的部分。该文档说:
要声明记录常量,请在声明末尾的括号中将每个字段的值指定为fieldName:value,并用分号分隔字段分配。这些值必须用常量表达式表示。
编译器告诉您这LB_NORMAL
不是一个常量表达式。我们不知道是什么LB_NORMAL
,但是它必须是与type兼容的常量表达式string
。例如:
const
LB_NORMAL = 'foo';
就足够了。甚至:
const
foo = 'foo';
bar = 'bar';
LB_NORMAL = foo + bar;
但是,您定义LB_NORMAL
,它不是常量表达式。您可能需要参考文档中的常量表达式以了解如何继续。
您似乎隐含在文本中,尽管不清楚,可悲的是您没有显示是什么LB_NORMAL
,那LB_NORMAL
是一个变量。好吧,变量不是常量表达式。如果LB_NORMAL
确实是变量,则还必须声明StylesEvalueArray
为变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句