2014-02-08 103 views
2

我可以定義記錄常數是這樣的:記錄常量可以記錄在Delphi 6中的記錄嗎?

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...); 

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

東西記錄常數可記錄的記錄,或者不是?我使用的是Delphi 6.(我意識到解決方法是將模板重新定義爲字段的單級記錄。)

+0

您可以從文檔中學習如何執行此操作:http://docwiki.embarcadero.com/RADStudio/en/Declared_Constants#Record_Constants –

+0

這與Delphi 6文檔中的描述相同。它只暗示,但實際上並沒有記錄記錄記錄的正確語法。 –

+0

當然可以。您只需遞歸閱讀文檔。 –

回答

5

是的,這是非常可能的,您幾乎可以知道如何去做:

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)); 

您只需在每個「級別」上遵循相同的模式。