delphi TFont类型和JSON互相转换的函数  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi TFont类型和JSON互相转换的函数


 做一个小项目中,要将TFont保存下来,想使用JSON格式,所以写了两个函数进行互相转换!

[Quote title=""]
function FontToJson(AFont: TFont): string;
var
Json: ISuperObject;
begin
Json := so;
Json.s['name'] := AFont.Name;
Json.I['size'] := AFont.Size;
Json.I['color'] := AFont.Color;
Json.B['bold'] := fsBold in AFont.Style;
Json.B['italic'] := fsItalic in AFont.Style;
Json.B['underline'] := fsUnderline in AFont.Style;
Result := Json.AsString;
end;

function JsonToFont(AJson: string): TFont;
var
Json: ISuperObject;
begin
Result := TFont.Create;
Json := so(AJson);
Result.Name := Json.s['name'];
Result.Size := Json.I['size'];
Result.Color := Json.I['color'];
if Json.B['bold'] then
Result.Style := Result.Style + [fsBold]
else
Result.Style := Result.Style - [fsBold];
if Json.B['italic'] then
Result.Style := Result.Style + [fsItalic]
else
Result.Style := Result.Style - [fsItalic];
if Json.B['underline'] then
Result.Style := Result.Style + [fsUnderline]
else
Result.Style := Result.Style - [fsUnderline];
end;
[/Quote]

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.033560991287231 seconds