初学者的初级问题,没了就175分了!(175分)

B

brt

Unregistered / Unconfirmed
GUEST, unregistred user!
有一A.dat文件,由若干相同结构数据组成,每组数据占55字节。
其中:第1-2字节为smallint型,3字节为shortint型,8-11字节为
single型,24-31字节为double型,其它字节数据没用。我想把它
转换为另一数据格式B.dat,每组数据占40字节,都为Integer型,
其中1-4字节是A.dat文件中1-2,3字节的数值之和,5-8字节为
A.dat文件8-11字节数值取整, 9-12字节为A.dat文件24-31字节
数值取整,其它字节数据为零。
 
你用openfile,然后用pchar去读,转化成整数计算
然后转化为pchar再写回去,中间有什么问题解决不了吗?
 
作个循环遍历a.dat,在循环体中读出各个元素,处理后得到新的rec,赋值给B.dat的新添加行.
不难做!
 
沒辦法﹐自己將文件讀出來﹐再根據自己判斷后﹐再寫到另一個文件中。你是不清楚怎么寫
還是不清楚要用到哪些函數﹖
 
用流来操作如何
 
or Tstringlist
 
做个RECORD,设定你的RECORD组字段,然后一读就出来了,很简单的
 
TYourRecrod = packed record
First: String[2];
Sencond: String[1];
Thrid: String[4];
//No used
Fourth: String[4];
Fifth: String[12];
//No used
Sixth: String[8];
Seventh: String[24];
end;

//读记录
var
YourRecord: TYourRecord;
DataFile: File of TYourRecord;
begin
AssignFile(DataFile, 'YourFile.Dat');
Reset(DataFile);
try
if not Eof(DataFile) then
read(DataFile, YourRecord);
finally
CloseFile(DataFile);
end;
end;

//写记录;你自己可以重新定义一个新记录.
var
var
YourRecord: TYourRecord;
DataFile: File of TYourRecord;
begin
AssignFile(DataFile, 'YourFile1.Dat');
Reset(DataFile);
Seek(DataFile, FileSize(DataFile));
try
write(DataFile, YourRecord;
finally
CloseFile(DataFile);
end;
end;
 
同意

TYourRecrod = packed record
First: String[2];
Sencond: String[1];
Thrid: String[4];
//No used
Fourth: String[4];
Fifth: String[12];
//No used
Sixth: String[8];
Seventh: String[24];
end;

//读记录
var
YourRecord: TYourRecord;
DataFile: File of TYourRecord;
begin
AssignFile(DataFile, 'YourFile.Dat');
Reset(DataFile);
try
if not Eof(DataFile) then
read(DataFile, YourRecord);
finally
CloseFile(DataFile);
end;
end;

//写记录;你自己可以重新定义一个新记录.
var
var
YourRecord: TYourRecord;
DataFile: File of TYourRecord;
begin
AssignFile(DataFile, 'YourFile1.Dat');
Reset(DataFile);
Seek(DataFile, FileSize(DataFile));
try
write(DataFile, YourRecord;
finally
CloseFile(DataFile);
end;
end;
 
用记录来实现比较好,同意楼上的说法
 
Brave:给段代码:)
hxcpa@163.com
 
用记录实现,同意楼上的说法;
 
我做过同样的程序,最方便的是定义一个二维数组,赋值不就行了(如果文件不是太大的话) 
 
好象不对呀!与我的提问不一致:)
 
有什么不对的你说明白了,我觉得dongberlin, 说的挺详细的了,
他只是没把你要转换的类型的数据结构写出来,你可以照着他写的
TYourRecrod = packed record
First: String[2];
Sencond: String[1];
Thrid: String[4];
//No used
Fourth: String[4];
Fifth: String[12];
//No used
Sixth: String;
Seventh: String[24];
end;
在定义一个新记录,然后分别针对你需要的每一项作类型转换
再写进去就可以了,明白了吗?可以结束了吗?
 
gzpbx你能把dongberlin未写的代码写出来吗!

 
呢泡我那,照着写不会吗?
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
977
SUNSTONE的Delphi笔记
S
S
回复
0
查看
799
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部