How to solve RTTI size issue for large Enum types in Delphi XE?
I get this error when I try to compile a unit with a Enum type with 5000+ values in Delphi开发者_如何转开发 XE
[DCC Error] uCities.pas(5834): E2575 RTTI for 'TCity' is too large; reduce scope with $RTTI or reduce type size
How can I solve this?
Things like
{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
didn't help.
thanks in advance
You're using an enum to list cities ??? That's new.
It's better using an lookup data structure than an enum.
EDIT: you can use, for example, an TClientDataset or you can use an TDictionary (from Generics.Collections unit) if you do any kind of lookup (get the string name of the city from an TCity value).
And help people here to help you: TCidade
will not make any sense to those that can't read Portuguese but with TCity
people can get a better understanding about what your problem is.
An Enum type with 5000+ values is not an Enum you wrote by hand. And an Enum that now has 5k values will have 10k tomorrow.
You should modify the code that generated the enum to generate simple constants instead. Use Integer (or Smallint) for the actual type. That should fix it for good.
Per Mason Wheeler, refactor the class to reduce the type size. Break it up into several smaller ones.
Source: Embarcadero forums
Edit: On closer reading, this may be tricky since you're dealing with an enum. One option might be to convert the enum values into integer constants (Const keyword) and change procedures to use integers.
Without going into discussion if 5k entries in an enum is justified - quick fix is to add =1 to your first enum item.
TCharsetChar= ( csSPACE=1, csEXCLAMATION_MARK, csQUOTATION_MARK, ...
Sometimes it is worthwhile to break the rules - for time savings, or performance. So here you are.
精彩评论