“已发布集合'%s'的大小为> 4字节”。如何解决此编译器错误? [英] "Size of published set '%s' is >4 bytes". How to fix this compiler error?

查看:77
本文介绍了“已发布集合'%s'的大小为> 4字节”。如何解决此编译器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组具有138个值的枚举值。

I have a set of enumeration values that have 138 values. Something like:

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;

编译时,我收到以下错误消息:

When compiling this I get the following error message:

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

关于如何在公开发布的房地产中包含这样大小的集合的任何想法?

Any idea on how I can include a set of this size inside a published property?

我需要之所以将其包含在已发布的部分中,是因为我正在使用OmniXMLPersistent将类保存为XML,并且只保存已发布的属性。

I need to include this set on the published section because I'm using OmniXMLPersistent to save the class into a XML and it only saves published properties.

推荐答案

可能是您需要以下技巧(我未使用OmniXML并且无法对其进行检查):

May be you need the following trick (I am not using OmniXML and can't check it):

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;

这篇关于“已发布集合'%s'的大小为> 4字节”。如何解决此编译器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆