在Delphi 6中,记录常量可以是记录的记录吗?

在Delphi 6中,记录常量可以是记录的记录吗?,delphi,syntax,Delphi,Syntax,我可以这样定义记录常量: const dialoghdr: DLGTEMPLATE = (style: 1; dwExtendedStyle: 2; cdit: 3; x: 4; y: 5; cx: 6; cy: 7); dialogitem: DLGITEMTEMPLATE = (style: 8; dwExtendedStyle: 9; x: 10; y: 11; cx: 12; cy: 13; id: 14); type template = packed r

我可以这样定义记录常量:

const
  dialoghdr: DLGTEMPLATE =
    (style: 1; dwExtendedStyle: 2; cdit: 3; x: 4; y: 5; cx: 6; cy: 7);
  dialogitem: DLGITEMTEMPLATE =
    (style: 8; dwExtendedStyle: 9; x: 10; y: 11; cx: 12; cy: 13; id: 14);
type
  template = packed record
    header: DLGTEMPLATE;
    item: DLGITEMTEMPLATE;
    end;
我可以定义这样的记录记录:

const
  dialoghdr: DLGTEMPLATE =
    (style: 1; dwExtendedStyle: 2; cdit: 3; x: 4; y: 5; cx: 6; cy: 7);
  dialogitem: DLGITEMTEMPLATE =
    (style: 8; dwExtendedStyle: 9; x: 10; y: 11; cx: 12; cy: 13; id: 14);
type
  template = packed record
    header: DLGTEMPLATE;
    item: DLGITEMTEMPLATE;
    end;
尽管编译器会接受这一点:

const mytemplate: template = (); // compiles!
有没有一种方法可以在()中实际放置常量?差不多

const mytemplate: template = 
    (header.style: 1; header.dwExtendedStyle: 2; header.cdit: 3...,
     item.style: 8; item.dwExtendedStyle: 9; item.x: 10...);


记录常量是否可以是记录的记录?我使用的是Delphi6。(我意识到一种解决方法是将模板重新定义为字段的单级记录。)

是的,这是非常可能的,而且您几乎知道如何做到这一点:

const mytemplate: template =
  (header: (style: 1; dwExtendedStyle: 2; cdit: 3; x: 4; y: 5; cx: 6; cy: 7);
   item: (style: 8; dwExtendedStyle: 9; x: 10; y: 11; cx: 12; cy: 13; id: 14));

您只需在每个“级别”上遵循相同的模式即可。

您可以从文档中了解如何做到这一点:这与Delphi 6文档的描述相同。它只暗示了记录的正确语法,但实际上并没有记录,确实如此。您只需要递归地阅读文档。