数据库文件又不是文本的设置textfile自然不行。
用二进制读。或者使用TFileStream.
你用你的程序读一个非文本的试试,一般不行。如一个exe文件。
数据库文件的特殊格式?他有何特殊,还不是一个文件。
格式对底层没有意义。

解决方案 »

  1.   

    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;
      

  2.   

    目的:加密一数据库文件.
    步踌:读入数据库文件(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;