为什么ini文件没有被保存? [英] Why ini file is not being saved?

查看:212
本文介绍了为什么ini文件没有被保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存unicode字符串.我有什么:

I am trying to save unicode string. There is what I have:

Uses IniFiles;
const
SZ_APP_NAME;

Procedure TForm1.SaveSettings;
var
  _MemIniU: TMemIniFile;
  SettingsPath: string;
begin
  SettingsPath := GetHomePath + PathDelim + SZ_APP_NAME + PathDelim;
  _MemIniU := TMemIniFile.Create(ChangeFileExt(SettingsPath, 'Settings.ini'),
    TEncoding.UTF8);
  try
    if Form1.WindowState <> TWindowState.wsMaximized then
    begin
      _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowLeft', Form1.Left);
      _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowTop', Form1.Top);
      _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowWidth', Form1.Width);
      _MemIniU.WriteInteger(SZ_APP_NAME, 'WindowHeight', Form1.Height);
      _MemIniU.WriteString(SZ_APP_NAME, 'UnicodeText', Edit1.Text);
    end;
  finally
    _MemIniU.Free;
  end;
end;

但是未创建ini文件.我做错了什么? RAD Studio XE5.

But ini file is NOT created. What I am doing wrong? RAD Studio XE5.

推荐答案

您必须调用TMemIniFile.UpdateFile将信息保存到文件中.

You have to call TMemIniFile.UpdateFile to save the information into the file.

文档非常清楚

TMemIniFile 缓冲对INI文件的所有更改.首次创建对象时,INI文件将被读取一次. INI文件中的数据存储在嵌套的字符串列表中. INI文件中的每个部分在最上面的字符串列表中占据一个元素,并且其中的每个元素本身都可以包含一个字符串列表.每个包含的字符串列表中的每个元素都代表该部分中的一个键.读取数据后,对数据的任何更改都将存储在内存中.要将数据从内存写回到关联的INI文件,请调用 UpdateFile 方法.

TMemIniFile buffers all changes to the INI file. The INI file is read once, when the object is first created. Data from the INI file is stored in nested string lists. Each section in the INI file occupies one element in the top-most string list, and each element in this may itself contain a string list. Each element in each of the contained string list represents a key within the section. After the data is read, any changes to the data are stored in memory. To write the data from memory back to the associated INI file, call the UpdateFile method.

DocWiki TMemIniFile

这篇关于为什么ini文件没有被保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆