Delphi中的记录文件类型如何保存读取?

dyfh 2003-10-17 09:02:52
TYPE
Temployee = record
name : string[10];
address : string[50];
end;
TemployeeFile = File Of Temployee;

var
EmployeeFile : TemployeeFile;

如何将多个记录以记录文件类型保存在文件中并依次读出?偶忘光了,手上也没资料了,哦了
...全文
71 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyfh 2003-10-17
  • 打赏
  • 举报
回复
谢谢,我全明白了:)
zzh26 2003-10-17
  • 打赏
  • 举报
回复
FileSize(DataFile)取得的是记录数,你看看我上面的程序就知道了;
seek(f,1);
表示移动到第二条
dyfh 2003-10-17
  • 打赏
  • 举报
回复
to zzh26(瞌睡)
下面这几句不太明白
n:=fileSize(f);
if (RecNo>=n) or (RecNo<0) then
begin
closeFile(f);
exit;
end;

在记录文件类型中使用filesize,得到的返回值就是记录的数量吗?
dyfh 2003-10-17
  • 打赏
  • 举报
回复
to zzh26(瞌睡)
FileSize(DataFile)取得文件尺寸,那么如何取得一个记录在文件中的大小,比如我需要在多个记录中记取第三或第四个记录的值,需要计算pos
zzh26 2003-10-17
  • 打赏
  • 举报
回复
function DelRecNo(FileName:string;RecNo:Integer):Boolean;
//删除第 RecNo条,第一条为 0
var
Svr:Temployee;
f:file of TTemployee;
n,i:integer;
begin
Result:=false;
if not(FileExists(FileName)) then exit;
AssignFile(f,FileName);
FileMode:=2;
reset(f);
n:=fileSize(f);
if (RecNo>=n) or (RecNo<0) then
begin
closeFile(f);
exit;
end;
for i:=n-1 downto RecNo+1 do
begin
seek(f,i);
Read(f,svr);
seek(f,i-1);
write(f,svr);
end;
seek(f,n-1);
Truncate(f);
closeFile(f);
Result:=true;
end;
aiunong 2003-10-17
  • 打赏
  • 举报
回复
学习 UP
zzh26 2003-10-17
  • 打赏
  • 举报
回复
下列代码用来向文件中追加一条记录:
var
PersonRec:TPersonRec;
DataFile:File of TPersonRec;
begin
AssignFile(DataFile, 'PersonS.dat');
// Open the file for read access.
Reset(DataFileF);
Seek(DataFile,FileSize(DataFile));
try
Write(DataFile,PersonRec);
finally
CloseFile(DataFile); // Close the file when finished.
end;
end;
Alanwn 2003-10-17
  • 打赏
  • 举报
回复
NO.1

5,385

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧