Delphi中简单的读/写记录.dat文件
由于某种原因,即使我昨天使用过,我的 OpenID 帐户也不再存在。但无论如何。
我需要将记录数据保存到 .dat 文件中。我尝试了很多搜索,但都是与数据库和BLOB的东西有关。我无法从中构建任何东西。
我有以下记录,
type
Scores = record
name: string[50];
score: integer;
end;
var rank: array[1..3] of scores;
我只需要一种简单的方法来保存和读取 .dat 文件中的记录数据。我有一本关于如何做到这一点的书,但那是在学校。
For some reason my OpenID account no longer exists even when I used it yesterday. But anyway.
I need to save record data into a .dat file. I tried a lot of searching, but it was all related to databases and BLOB things. I wasn't able to construct anything from it.
I have the following record
type
Scores = record
name: string[50];
score: integer;
end;
var rank: array[1..3] of scores;
I just need a simple way of saving and reading the record data from a .dat file. I had the book on how to do it, but that's at school.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还应该查看方法的
文件
。这有点过时了,但它是学习如何使用文件的好方法。
由于使用此方法无法将动态数组(包括普通字符串)的记录存储到文件中,因此不支持 unicode 字符串。但是
string[50]
基于 ShortStrings,因此您的记录已经是非 unicode...写入文件
从文件读取
You should also take a look at the
file of
-method.This is kinda out-dated, but it's a nice way to learn how to work with files.
Since records with dynamic arrays (including ordinary strings) can't be stored to files with this method, unicode strings will not be supported. But
string[50]
is based on ShortStrings and your record is therefore already non-unicode...Write to file
Read from file
使用流。这是一个简单的演示(只是演示 - 实际上不需要每次都重新打开文件流):
Use streams. Here is a simple demo (just demo - in practice there is no need to reopen file stream every time):
查看“blockread”和/或“blockwrite”下的帮助。大概会有一个例子
Look in the help under "blockread" and or "blockwrite". There probably will be an example