【发布时间】:2011-08-16 18:39:07
【问题描述】:
我正在尝试读取和写入用户设置的 app.config 文件。我找到了一个使用配置文件的代码的 sn-p。我终于让它编译并运行了,但它似乎对 App.config 文件没有任何作用。
代码如下:
Method MainForm1.Button1.Click(sender: System.Object; e: System.EventArgs);
var
config : System.Configuration.Configuration;
begin
config:=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add('PreferenceToRemember','value1');
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection('appSettings');
end;
它正在编译,没有任何错误,但我不知道它是否在做任何事情。
代码有什么问题吗?我需要能够写/读一个部分和写/读一个键/值。提前致谢。
更新:我没有使用 ConfigurationManager,而是使用 Properties.Settings.Default。但是,我在写入和读取时遇到了一些问题,尽管程序没有任何错误并且代码看起来很简单。
如何在代码中读取和写入 Properties.Settings.Default?
【问题讨论】:
-
查看此堆栈溢出答案:stackoverflow.com/questions/1157378/…
标签: configuration app-config delphi-prism read-write