delphi 如何把字体颜色保存到数据库
1、用记事本打开dfm文件会看到类似这样的文本: object Label1: TLabel Left = 24 Top = 32 Width = 140 Height = 46 Caption = #20445#23384#23454#20363 Font.Charset = GB2312_CHARSET Font.Color = clBlue Font.Height = -35 Font.Name = #24494#36719#38597#40657 Font.Style = [fsBold, fsUnderline, fsStrikeOut] ParentFont = False end

2、自己写了个直接保存成文件文件的,记录一下 unit Font2String; interface uses Classes, SysUtils, Dialogs, Graphics; function Font2File(AFont: TFont; APath: string): Boolean; function File2Font(APath: string; AFont: TFont): Boolean; implementation function Font2File(AFont: TFont; APath: string): Boolean; var FD: TFontDialog; begin Result := False; FD := TFontDialog.Create(nil); try FD.Font.Assign(AFont); WriteComponentResFile(APath, FD); Result := True; finally FD.Free; end; end;

3、function File2Font(APath: string; AFont: TFont): Boolean; var FD: TFontDialog; begin Result := False; FD := TFontDialog.Create(nil); try ReadComponentResFile(APath, FD);//如果此外为nil,下面的注册去掉 AFont.Assign(FD.Font); Result := True; finally FD.Free; end; end;

4、//initialization //RegisterClass(TFontDialog); end.

5、例子:procedure TForm1.Button1Click(Sender: TObject); begin Font2File(Label1.Font, 'd:\Font.fnt');//把字体保存成文件 end; procedure TForm1.Button2Click(Sender: TObject); begin File2Font( 'd:\Font.fnt', Label2.Font);//从文件里读取字体 end;
