2016-12-10 102 views
2

我需要將下面的結構轉換爲delphi。我懷疑這個「:4」的價值在「保留」和「版本」成員中意味着什麼。它看起來干擾了結構的大小!任何人有任何提示?將C結構轉換爲delphi

typedef struct _FSRTL_COMMON_FCB_HEADER { 
    CSHORT  NodeTypeCode; 
    CSHORT  NodeByteSize; 
    UCHAR   Flags; 
    UCHAR   IsFastIoPossible; 
    UCHAR   Flags2; 
    UCHAR   Reserved :4; 
    UCHAR   Version :4; 
    PERESOURCE Resource; 
    ... 
+0

比特數。 –

+1

對於記錄,因爲也標記帕斯卡:免費帕斯卡支持位域。 –

回答

3

這些是位域。他們不直接支持德爾福,但有解決方法,請參閱here,尤其是here

+0

啊,謝謝,我只是想發佈相同的鏈接(第二個)。

6

正如已經說過的評價,這是一個位字段,即一組一起形成一個字節,字或雙字的位。

最簡單的解決方法是:http://rvelthuis.de/articles/articles-convert.html#bitfields,到烏利已經鏈接:

type 
    _FSRTL_COMMON_FCB_HEADER = record 
    private 
    function GetVersion: Byte; 
    procedure SetVersion(Value: Byte); 
    public 
    NodeTypeCode: Word; 
    ... 
    ReservedVersion: Byte; // low 4 bits: reserved 
          // top 4 bits: version 
    // all other fields here 

    property Version: Byte read GetVersion write SetVersion; 
    // Reserved doesn't need an extra property. It is not used. 
    end; 

    ... 

implementation 

function _FSRTL_COMMON_FCB_HEADER.GetVersion: Byte;  
begin 
    Result := (ReservedVersion and $F0) shr 4; 
end; 

procedure _FSRTL_COMMON_FCB_HEADER.SetVersion(Value: Byte); 
begin 
    ReservedVersion := (Value and $0F) shl 4; 
end; 

一個不太簡單的(但更普遍的)解決方案和解釋可以在我的文章中找到。