type TFontRecord = record CharSet:Byte; Color:Integer; Name:string; Size:Integer; Style:Byte; PixelsPerInch:Integer; Pitch:0..2; Height:Integer; end;procedure FontRecordToFont(FontRecord:TFontRecord;Font:TFont); begin with FontRecord do begin Font.Charset:=CharSet; Font.Color:=Color; Font.Name:=Name; Font.Size:=Size; case Pitch of 0:Font.Pitch:=fpDefault; 1:Font.Pitch:=fpVariable; 2:Font.Pitch:=fpFixed; end; Font.Style:=IntToFontStyles(Style); end; end;function FontToFontRecord(Font:TFont):TFontRecord; begin with Font do begin Result.CharSet:=Charset; Result.Color:=Color; Result.Height:=Height; Result.Name:=Name; case Pitch of fpDefault:Result.Pitch:=0; fpVariable:Result.Pitch:=1; fpFixed:Result.Pitch:=2; end; Result.Size:=Size; Result.PixelsPerInch:=PixelsPerInch; Result.Style:=FontStylesToInt(Style); end; end;function FontStylesToInt(FontStyles:TFontStyles):Byte; var T:Integer; begin T:=0; if fsBold in FontStyles then T:=T+8; if fsItalic in FontStyles then T:=T+4; if fsUnderline in FontStyles then T:=T+2; if fsStrikeOut in FontStyles then T:=T+1; Result:=T; end;function IntToFontStyles(FontInteger:Byte):TFontStyles; var FontT:TFontStyles; begin if (FontInteger>15) then begin Result:=[]; Exit; end; FontT:=[]; if FontInteger>=8 then begin FontT:=FontT+[fsBold]; FontInteger:=FontInteger-8; end; if FontInteger>=4 then begin FontT:=FontT+[fsItalic]; FontInteger:=FontInteger-4; end; if FontInteger>=2 then begin FontT:=FontT+[fsUnderline]; FontInteger:=FontInteger-2; end; if FontInteger>=1 then FontT:=FontT+[fsStrikeOut]; Result:=FontT; end;
myinifile:=tinifile.create('ini文件路径');
label1.font.nema:=myinifile.readstring('font','fontname','宋体');
label1.font.size:=myinifile.readinteger('font','fontsize',8);//第三个参数为默认值tformclose:
myinifile.writestring('font','fontname',label1.font.nema);
myinifile.writeinteger('font','fontsize',label1.font.size);
myinifile.destroy;
CharSet:Byte;
Color:Integer;
Name:string;
Size:Integer;
Style:Byte;
PixelsPerInch:Integer;
Pitch:0..2;
Height:Integer;
end;procedure FontRecordToFont(FontRecord:TFontRecord;Font:TFont);
begin
with FontRecord do
begin
Font.Charset:=CharSet;
Font.Color:=Color;
Font.Name:=Name;
Font.Size:=Size;
case Pitch of
0:Font.Pitch:=fpDefault;
1:Font.Pitch:=fpVariable;
2:Font.Pitch:=fpFixed;
end;
Font.Style:=IntToFontStyles(Style);
end;
end;function FontToFontRecord(Font:TFont):TFontRecord;
begin
with Font do
begin
Result.CharSet:=Charset;
Result.Color:=Color;
Result.Height:=Height;
Result.Name:=Name;
case Pitch of
fpDefault:Result.Pitch:=0;
fpVariable:Result.Pitch:=1;
fpFixed:Result.Pitch:=2;
end;
Result.Size:=Size;
Result.PixelsPerInch:=PixelsPerInch;
Result.Style:=FontStylesToInt(Style);
end;
end;function FontStylesToInt(FontStyles:TFontStyles):Byte;
var
T:Integer;
begin
T:=0;
if fsBold in FontStyles then
T:=T+8;
if fsItalic in FontStyles then
T:=T+4;
if fsUnderline in FontStyles then
T:=T+2;
if fsStrikeOut in FontStyles then
T:=T+1;
Result:=T;
end;function IntToFontStyles(FontInteger:Byte):TFontStyles;
var
FontT:TFontStyles;
begin
if (FontInteger>15) then
begin
Result:=[];
Exit;
end;
FontT:=[];
if FontInteger>=8 then
begin
FontT:=FontT+[fsBold];
FontInteger:=FontInteger-8;
end;
if FontInteger>=4 then
begin
FontT:=FontT+[fsItalic];
FontInteger:=FontInteger-4;
end;
if FontInteger>=2 then
begin
FontT:=FontT+[fsUnderline];
FontInteger:=FontInteger-2;
end;
if FontInteger>=1 then
FontT:=FontT+[fsStrikeOut];
Result:=FontT;
end;
http://kmok.cn
procedure WriteFontToIni(Ini: TIniFile; Session, Name: string; Font: TFont);
var
data: TLogFont; function Buf2Str(const buf; Len: Integer): string;
const
Chars: string = '0123456789ABCDEF';
var
i: Integer;
p: PByte;
begin
setlength(result, len*2);
p := @buf;
for i := 0 to len - 1 do
begin
result[i shl 1+1] := Chars[p^ shr 4];
result[i shl 1+2] := Chars[p^ and $F];
inc(p);
end;
end;begin
getobject(font.handle, sizeof(data), @data);
Ini.WriteString(Session, Name, Buf2Str(data));
end;读:
procedure ReadFontFromIni(Ini: TIniFile; Session, Name: string; Font: TFont);
var
data: TLogFont;
procedure Str2Buf(S: string; var Buf);
var
i: Integer;
p: PByte;
begin
p := @buf;
for i := 1 to length(s) do
begin
case s[i] of
'0'..'9': p^ := p^ shl 4 + byte(s[i]) - byte('0');
'A'..'F': p^ := p^ shl 4 + byte(s[i]) - byte('A') + 10;
'a'..'f': p^ := p^ shl 4 + byte(s[i]) - byte('a')+10;
end;
if i and 1 = 0 then
inc(p);
end;
end;begin
Str2Buf(Ini.ReadString(Session, Name, ''), data);
Font.Handle := CreateFontIndirect(@data);
end;
Ini.WriteString(Session, Name, Buf2Str(data));
Font.Handle := CreateFontIndirect(@data);
都有问题!