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


本文整理自网络,侵删。

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


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;

相关阅读 >>

Delphi 泛型 tdictionary<string,string>

Delphi 修改盘符名称

Delphi常用日期函数

Delphi 试试带参数的 exit

Delphi判断sql server 服务是否断开

Delphi xe6调用android手机标准功能

Delphi穿墙自启动下载者4.0

Delphi让程序运行后自我删除或恢复名称

Delphi 文件路径结尾去掉“\”

Delphi 查找指定目录,指定扩展名的所有文件名

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...