2010-01-23 26 views
3

我有一組枚舉值有138個值。喜歡的東西:「發佈集'%s'的大小大於4個字節」。如何解決這個編譯器錯誤?

type 
    TSomething = (sOne, sTwo, sThree, ..., ..., sOnehundredAndThirtyeight); 
    TSomethings = set of TSomething; 

.... 

    TSomething = class(TPersistent) 
    private 
    fSomethings: TSomethings; 
    published 
    property Somethings: TSomethings read fSomethings write fSomethings; 
    end; 

當編譯這個我收到以下錯誤信息:

[DCC Error] uProfilesManagement.pas(20): E2187 Size of published set 'Something' is >4 bytes 

我如何能包括一組這種規模已發佈物業內的任何想法?

我需要包括這套上發佈的部分,因爲我使用OmniXMLPersistent的類保存到一個XML,它不僅節省了發佈的屬性。

+0

是否真如說的錯誤消息%s嗎?如果是的話,你應該把它報告給質量中心作爲一個錯誤,因爲他們顯然忘記了調用Format或者沒有通過這個錯誤信息傳遞屬性名稱。 – dummzeuch 2010-01-23 19:08:53

+0

不,錯誤消息是「[DCC錯誤] uProfilesManagement.pas(20):E2187問題文本上指出的已發佈集'Something'的大小大於4個字節」。 – smartins 2010-01-24 11:11:42

回答

2

可能是你需要下面的技巧(我沒有使用OmniXML並不能檢查):

type 
    TSomething = (sOne, sTwo, sThree, ..., sOnehundredAndThirtyeight); 
    TSomethings = set of TSomething; 

    TSomethingClass = class(TPersistent) 
    private 
    fSomethings: TSomethings; 
    function GetSomethings: string; 
    procedure SetSomethings(const Value: string); 
    published 
    property Somethings: string read GetSomethings write SetSomethings; 
    end; 


{ TSomethingClass } 

function TSomethingClass.GetSomethings: string; 
var 
    thing: TSomeThing; 
begin 
    Result:= ''; 
    for thing:= Low(TSomething) to High(TSomething) do begin 
    if thing in fSomethings then Result:= Result+'1' 
    else Result:= Result+'0'; 
    end; 
end; 

procedure TSomethingClass.SetSomethings(const Value: string); 
var 
    I: Integer; 
    thing: TSomeThing; 
begin 
    fSomethings:= []; 
    for I:= 0 to length(Value) - 1 do begin 
    if Value[I+1] = '1' then Include(fSomethings, TSomething(I)); 
    end; 
end; 
+0

感謝您的回覆。有關如何使用GetSetProp和SetSetProp(來自TypInfo單元)自動將該集合作爲字符串並將其設置回字符串的原始狀態的任何想法?我剛剛爲此創建了另一個問題:http://stackoverflow.com/questions/2127079/how-to-use-getsetprop-and-setsetprop-from-typinfo-unit – smartins 2010-01-24 12:52:06

1

不幸的是,編譯器不允許被包含在發佈的部分設定大於32位。一組字節的大小可以通過High(set) div 8 - Low(set) div 8 + 1來計算。

您可以降低設定大小,或使用而不是一組自定義類,也可以枚舉分成幾組,每個的大小爲32位。

+0

感謝您的回覆。拆分枚舉將涉及到應用程序代碼的大量更改,因此無法解決問題。任何想法如何創建一個可以複製集合的自定義類? – smartins 2010-01-23 17:20:51

+0

@smartin:不幸的是你需要18個字節。也許將它轉換成足夠大的字節數組? – 2010-01-23 17:38:02

相關問題