• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

delphi颜色,字体保存到INI文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

颜色转换成整型保存{也可以用ColorToString  / stringTOColor}
字体用下面的函数转换成字符串,然后保存

unit xFonts;

interface

uses Classes, Graphics, SysUtils;

procedure StringToFont(sFont: string; Font: TFont; bIncludeColor: Boolean = True);
function FontToString(Font: TFont; bIncludeColor: Boolean = True): string;

implementation

const
  csfsBold      = '|Bold';
  csfsItalic    = '|Italic';
  csfsUnderline = '|Underline';
  csfsStrikeout = '|Strikeout';

  //
  // Expected format:
  //   "Arial", 9, [Bold], [clRed]
  //
procedure StringToFont(sFont: string; Font: TFont; bIncludeColor: Boolean = True);
var
  P     : Integer;
  sStyle: string; 
begin
  with Font do
    try
      // get font name
      P := Pos(',', sFont);
      name := Copy(sFont, 2, P - 3);
      Delete(sFont, 1, P);

      // get font size
      P := Pos(',', sFont);
      Size := StrToInt(Copy(sFont, 2, P - 2));
      Delete(sFont, 1, P);

      // get font style
      P := Pos(',', sFont);
      sStyle := '|' + Copy(sFont, 3, P - 4);
      Delete(sFont, 1, P);

      // get font color
      if bIncludeColor then Color := StringToColor(Copy(sFont, 3, Length(sFont) - 3));

      // convert str font style to
      // font style
      Style := [];
      if (Pos(csfsBold, sStyle) > 0) then Style := Style + [fsBold];
      if (Pos(csfsItalic, sStyle) > 0) then Style := Style + [fsItalic];
      if (Pos(csfsUnderline, sStyle) > 0) then Style := Style + [fsUnderline];
      if (Pos(csfsStrikeout, sStyle) > 0) then Style := Style + [fsStrikeOut];
    except
    end;
end;

//
// Output format:
//   "Aril", 9, [Bold|Italic], [clAqua]
//
function FontToString(Font: TFont; bIncludeColor: Boolean = True): string;
var
  sStyle: string;
begin
  with Font do
  begin
    // convert font style to string
    sStyle := '';
    if (fsBold in Style) then sStyle := sStyle + csfsBold;
    if (fsItalic in Style) then sStyle := sStyle + csfsItalic;
    if (fsUnderline in Style) then sStyle := sStyle + csfsUnderline;
    if (fsStrikeOut in Style) then sStyle := sStyle + csfsStrikeout;

    if ((Length(sStyle) > 0) and ('|' = sStyle[1])) then
      sStyle := Copy(sStyle, 2, Length(sStyle) - 1);

    Result := Format('"%s", %d, [%s]',[name, Size, sStyle]);
    if bIncludeColor then
      Result := Result + Format(', [%s]',[ColorToString(Color)]);
  end;
end;

end.

{对INI文件的操作,这里就在叙述了,需要的朋友 必应一下 一大堆}

文档转载『http://bbs.csdn.net/topics/100124538』


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi中StrToIntDef函数的应用发布时间:2022-07-18
下一篇:
DelphiXE8如何删除Castalia这个渣渣发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap