小编Mir*_*láž的帖子

Delphi字典保存/加载.TDictionary不可序列化?

TDictionary: SaveToFile/LoadFromFile

多么优雅的解决方案!首先,一切都按预期运行.

内容以JSON格式保存到文件中,该格式看起来正确.但重新加载文件后,出现了一个问题:

Type
  TEnumCategTypes = ( e_SQL1, e_VBA, e_Text );
  TCategParams = class
    fontStyles  : TFontStyles;
    rgbColor    : COLORREF;
    end;

  TdictCategory = class ( TDictionary<TEnumCategTypes, TCategParams> )
    public
      public class function LoadFromFile( const AFileName: string ): TdictCategory;
      public class procedure SaveToFile( const AFileName: string; dict: TdictCategory );
    end;

implementation

class procedure TdictCategory.SaveToFile( const AFileName: string; dict: TdictCategory );
var
  stream : TStringStream;
begin
  try
    stream := TStringStream.Create( TJson.ObjectToJsonString( dict ) ) ;
    stream.SaveToFile( AFileName ) …
Run Code Online (Sandbox Code Playgroud)

delphi serialization tdictionary

2
推荐指数
1
解决办法
802
查看次数

标签 统计

delphi ×1

serialization ×1

tdictionary ×1