数据库文件

Dale46 2000-03-25 07:47:00
delphi中,小弟想将一数据库文件(设为textfile)读入变量(设为ansistring)中,但始终不能将数据库文件完全读入,
是否应为数据库文件的特殊格式造成的,如果是,怎样解决?(注:程序在读入其他文件时,均能完全读入).thanks
...全文
176 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dale46 2000-03-30
  • 打赏
  • 举报
回复
目的:加密一数据库文件.
步踌:读入数据库文件(1.db)到串(a)中,取出串中每个字符的ascii(function ord),通过一定方式的运算,得到新的串,返回字符(function chr),再写入到文件(1.db)
问题:只能将数据库文件(1.db)的一部分读入,但该程序对文本文件一切正常.
拜托帮忙改正一下,谢谢
源程序:
var
f1,f2:textfile;
test:ansistring;
a:char;
b,code:integer;
c:string;

begin
assignfile(f1,'c:\1');
assignfile(f2,'c:\2');
reset(f1);
rewrite(f2);

while not eof(f1) do
begin
while not eoln(f1) do
begin
read(f1,test);
len:=length(test);
for i:=1 to len do
begin
a:=test[i];
b:=ord(a);
str(b,c);
if length(c)<2 then c:='00'+c else
if length(c)<3 then c:='0'+c;
write(f2,c);
end;
end;
readln(f1);
writeln(f2);
end;
kxy 2000-03-26
  • 打赏
  • 举报
回复
数据库文件又不是文本的设置textfile自然不行。
用二进制读。或者使用TFileStream.
你用你的程序读一个非文本的试试,一般不行。如一个exe文件。
数据库文件的特殊格式?他有何特殊,还不是一个文件。
格式对底层没有意义。
kxy 2000-03-26
  • 打赏
  • 举报
回复
1)
var
f1 : File;
begin
Assign(f1,'xxxx');
blockRead(f1,buf,len);
end;

2)
var
fs : tFileStream;
ms : tMemoryStream;
begin
fs := TFileStream.Create("xxx");
ms := TMemoryStream.Create;
ms.LoadFromStream(fs);
end;

3)
ms.loadFromFile('xxxx') //ms是 TMemoryStream;
Dale46 2000-03-26
  • 打赏
  • 举报
回复
怎样用二进制读?
lybt 2000-03-25
  • 打赏
  • 举报
回复
强类型语言!?

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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