//写配置文件
procedure WriteToIni(Const AFont : TFont);
var IniFile:TInifile;
FileName:String;
begin
FileName:=ExtractFilePath(Application.ExeName)+'\PFont.ini';
IniFile:=TIniFile.Create(FileName);
IniFile.WriteString('Font', 'FontName',AFont.Name);
IniFile.WriteInteger('Font', 'FontSize',AFont.Size);
IniFile.WriteBool('Font','FontBold',fsBold in AFont.Style);
IniFile.WriteBool('Font','FontItalic',fsItalic in AFont.Style);
IniFile.WriteInteger('Font', 'FontColor',AFont.Color);
IniFile.Free;
end;//读配置文件
procedure readfromIni(var aFontName: String;aFontSize: Integer;AFontstyle: TFontStyles;aFontColor: TColor);
var IniFile:TInifile;
FileName:String;
B:Boolean;
begin
FileName:=ExtractFilePath(Application.ExeName)+'\PFont.ini';
IniFile:=TIniFile.Create(FileName); aFontName:=IniFile.ReadString('Font','FontName','');
aFontSize:=StrToInt(IniFile.ReadString('Font','FontSize',''));
B:=IniFile.ReadBool('Font','FontBold',false);
if b then
aFontStyle := aFontStyle + [fsbold];
B:=IniFile.ReadBool('Font','FontItalic',false);
if b then
aFontStyle:=aFontStyle + [fsItalic];
aFontColor:=StrToInt(IniFile.ReadString('Font','FontColor',''));
IniFile.Free;
end;//
procedure TForm1.FormShow(Sender: TObject);
var aFontName: String;aFontSize: Integer;aFontColor: TColor;AFontstyle: TFontStyles;
Size:Integer;
begin
Size:=11;
readfromIni(AFontName,AFontSize,AFontStyle,AFontColor);
Form1.Font.Name:=AFontName;
ShowMessage(Form1.Font.Name);
ShowMessage(IntToStr(Form1.Font.Size));
Form1.Font.Size:=AFontSize;
ShowMessage(IntToStr(Form1.Font.Color));
Form1.Font.Color:=AFontColor;
Form1.Font.Style:=AFontStyle;
ADOQuery1.Open;
end;现在的问题是:
ShowMessage(IntToStr(Form1.Font.Size));
显示出来是12;
但是Form1.Font.Size:=AFontSize;之后就是172444272
如果Form1.Font.Size:=Size;就正常为11
Form1.Font.Color:=AFontColor也是类似问题,我不知道错什么地方,为什么出现这样问题,请救帮助
procedure WriteToIni(Const AFont : TFont);
var IniFile:TInifile;
FileName:String;
begin
FileName:=ExtractFilePath(Application.ExeName)+'\PFont.ini';
IniFile:=TIniFile.Create(FileName);
IniFile.WriteString('Font', 'FontName',AFont.Name);
IniFile.WriteInteger('Font', 'FontSize',AFont.Size);
IniFile.WriteBool('Font','FontBold',fsBold in AFont.Style);
IniFile.WriteBool('Font','FontItalic',fsItalic in AFont.Style);
IniFile.WriteInteger('Font', 'FontColor',AFont.Color);
IniFile.Free;
end;//读配置文件
procedure readfromIni(var aFontName: String;aFontSize: Integer;AFontstyle: TFontStyles;aFontColor: TColor);
var IniFile:TInifile;
FileName:String;
B:Boolean;
begin
FileName:=ExtractFilePath(Application.ExeName)+'\PFont.ini';
IniFile:=TIniFile.Create(FileName); aFontName:=IniFile.ReadString('Font','FontName','');
aFontSize:=StrToInt(IniFile.ReadString('Font','FontSize',''));
B:=IniFile.ReadBool('Font','FontBold',false);
if b then
aFontStyle := aFontStyle + [fsbold];
B:=IniFile.ReadBool('Font','FontItalic',false);
if b then
aFontStyle:=aFontStyle + [fsItalic];
aFontColor:=StrToInt(IniFile.ReadString('Font','FontColor',''));
IniFile.Free;
end;//
procedure TForm1.FormShow(Sender: TObject);
var aFontName: String;aFontSize: Integer;aFontColor: TColor;AFontstyle: TFontStyles;
Size:Integer;
begin
Size:=11;
readfromIni(AFontName,AFontSize,AFontStyle,AFontColor);
Form1.Font.Name:=AFontName;
ShowMessage(Form1.Font.Name);
ShowMessage(IntToStr(Form1.Font.Size));
Form1.Font.Size:=AFontSize;
ShowMessage(IntToStr(Form1.Font.Color));
Form1.Font.Color:=AFontColor;
Form1.Font.Style:=AFontStyle;
ADOQuery1.Open;
end;现在的问题是:
ShowMessage(IntToStr(Form1.Font.Size));
显示出来是12;
但是Form1.Font.Size:=AFontSize;之后就是172444272
如果Form1.Font.Size:=Size;就正常为11
Form1.Font.Color:=AFontColor也是类似问题,我不知道错什么地方,为什么出现这样问题,请救帮助
解决方案 »
- 新手,请教关于quickreport的问题
- 不对呀,大家发了这么多贴子.为什么没有一个是正确的了,高手在哪?出山相救一下小弟吧
- delphi 6 Ado 访问SQL数据库的一段程序原码,请高手指点一下其中的不足。
- 用针打怎么打票据啊,?第一次操作打印机
- 调用DLL中的窗口,以非模态方法显示,不法接收键盘消息不知为何?以模态方法显示一切正常。
- 夜,深了。还有谁在,聊聊?如果你没有事做的话!
- 求助:关于数据窗口中的数据的显示问题
- 动态dsn
- 【菜鸟问题】怎么自己重画TLabel控件,实现Label带下划线?不改字体
- 一个关于软件下载的问题
- ◆◆在IntraWeb下有哪种控件支持报表打印,rave? fastreport ? 水晶报表?◆◆
- same question ?
var IniFile:TInifile;
FileName:String;
B:Boolean;
begin
FileName:=ExtractFilePath(Application.ExeName)+'\PFont.ini';
IniFile:=TIniFile.Create(FileName); aFontName:=IniFile.ReadString('Font','FontName','');
aFontSize:=StrToInt(IniFile.ReadString('Font','FontSize',''));
B:=IniFile.ReadBool('Font','FontBold',false);
if b then
aFontStyle := aFontStyle + [fsbold];
B:=IniFile.ReadBool('Font','FontItalic',false);
if b then
aFontStyle:=aFontStyle + [fsItalic];
aFontColor:=StrToInt(IniFile.ReadString('Font','FontColor',''));
IniFile.Free;
end;
把过程改成
procedure readfromIni(var aFontName: String;var aFontSize: Integer;
var AFontstyle: TFontStyles; var aFontColor: TColor);
另外你显示的都是form1的属性,你还没有把读出的属性付值给form1
1、看看ini文件的实际内容是什么;
2、需要读整数的地方直接用ReadInteger来读,而不是用ReadString读取之后再StrToInt