从 IniFile 读取 2 行
再试一次。根据建议,添加我确实理解的代码段。我对必须将 4 位信息保存在两行中这一事实感到满意,如下所示:
IniFile.WriteString('TestSection','Name','Country');
IniFile.WriteString('TestSection','City','Street');
我的问题更多是有关将此信息加载回表单中。例如,如果在我的 IniFile 中我保存了以下代码,则
[TestSection]
John=Uk
London=barlystreet
Mike=Spain
Madrid=eduardostrata
Emma=USA
New York=1st Avenue
在 IniFile 中组成了信息。通过上面的代码添加。 现在我的问题是:例如,当我在编辑框中键入 Mike 时,我如何加载其余的所属信息。(西班牙,马德里,eduardostrata)。
Trying again. On advice, adding the piece of code that I do understand. I am fine with the fact that I have to save 4 bits of information in two lines like so:
IniFile.WriteString('TestSection','Name','Country');
IniFile.WriteString('TestSection','City','Street');
My question is more about loading this information back into the form. If in my IniFile I have saved for example the following code
[TestSection]
John=Uk
London=barlystreet
Mike=Spain
Madrid=eduardostrata
Emma=USA
New York=1st Avenue
Made up information in the IniFile. Added through the code above.
Now my question is: How could I load for example, when I type in an edit box Mike, the rest of the belonging information.(Spain, Madrid,eduardostrata).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
INI 文件不是这样工作的。您保存
name=value
对,并且必须有一种方法将它们关联起来。也许这可以帮助您开始:
您的 INI 文件中的结果包含:
加载回来:
所以您可能可以弄清楚这是如何工作的。该部分([] 中的部分)是人名,名称/值对是位置及其相应的值(例如,“Country=Spain”)。
That's not how an INI file works. You save
name=value
pairs, and have to have a way to associate them.Maybe this can help you get started:
Results in your INI file containing:
To load back:
So you can probably figure out how this works. The section (the part in []) is the person's name, and the name/value pairs are the location and it's corresponding value (for instance, 'Country=Spain').
您显然不了解 INI 文件的工作原理。如果约翰和戴夫都住在纽约怎么办? INI 文件中不能有两个同名的键。 (此外,您不应依赖每个部分中行的顺序。)
因此,您需要重新考虑如何保存数据。一个非常简单的解决方案是使用纯文本文件,其中每一行都是数据库中的一个项目,并且字段之间用竖线 (|) 等分隔:
如何读取此文件?嗯,这很简单,您应该知道如何做到这一点。如果您有非常具体的问题,请随时提问。
INI 文件的用途
那么,INI 文件的用途是什么? INI 文件的典型应用是保存程序设置。例如,当您退出文本编辑器时,它可能会将设置保存到settings.ini:
etc。这是由
etc完成的。当您下次启动应用程序时,它会读取该文件以恢复设置:
etc。 ,其中最后一个参数是默认值(以防 INI 文件中缺少该字段)。请注意,在每个部分中,键都是唯一的(并且需要如此),并且我们不关心每个部分内键的相对顺序。
You have clearly not understood how INI files work. What if both John and Dave live in New York? You cannot have two keys with the same name in an INI file. (In addition, you shouldn't rely on the ordering of the lines within each section.)
You thus need to rethink how you save your data. A very simple solution is to use a plain text file in which each line is an item in your database, and the fields are seperated by, for instance, a vertical line (|):
How to read this file? Well, that is trivial, and you should know how to do that. If you have a very specific question, then feel free to ask.
What INI files are for
But what are INI files for, then? Well, a typical application of a INI file is to save program settings. For instance, when you quit a text editor, it might save the settings to settings.ini:
etc. This is done by
etc. And when you start the application the next time, it will read the file to restore the settings:
etc., where the last parameters are the default values (in case the field is missing in the INI file). Notice that in each section, the keys are unique (and need to be), and that we don't care about the relative order of the keys inside each section.
创建所需关系的最简单方法是将用户的所有详细信息放在一行文本中。这不是 INI 文件的工作。你的问题是如何解析字符串。
首先,为什么需要保存“重复密码”?这对我来说没有意义。通常,用户界面会要求用户重复密码作为一种验证形式,但这就是它的全部好处。存储它以供以后检索没有任何好处。
我认为您需要保存用户的名字、姓氏和密码(3 个字符串)。看看下面的代码。
该文件将如下所示
现在,如何加载它...
现在...距离“好代码”还很远,但现在您至少知道一种方法来完成您的工作。希望有帮助。
The easiest way to create the relationship you want is to have all of a user's details on 1 line of text. This is not a job for INI files. Your issue is how to parse strings.
First of all, why do you need to save the "repeat password"? that doesn't make sense to me. Usually a UI will ask the user to repeat the password as a form of validation, but that's all it's good for. There's no benefit in storing it for later retrieval is there.
I think you need to save the user's first_name, last_name, and password (3 strings). Have a look at the following piece of code.
The file will look this
Now, how to load it...
Now... this far from "good code" but now you know at least 1 way to do your thing. Hope that helps.