function BlobContentToString(const FileName:string):string;with TFileStream.create(FileName,fmOpenRead) do
  Read(Result, size);我想把文件读到String里去,这个不行别人告诉我这样读
a := TFileStream.Create('d:\a.txt', fmOpenRead);
showmessage(inttostr(a.Read(s[1], 10)));
a.Free;
showmessage(s);怎么显示0和‘’呢?没读进去呀。

解决方案 »

  1.   

    我的主页有完整转程序,有问题请留言!!http://haitian.myrice.com/SoftRes.htmDELPHI精选-》文件<--->16进制字符(互转) 
      

  2.   

    不明白你想干什么啊?如果是文本拿就用stringlist.loadfromfile,如果是别的二进制文件那么还是用filestream比较好一些
      

  3.   

    with TFileStream.create(FileName,fmOpenRead) do
      Read(PChar(Result)^, size);  这句改成这样才行.
      

  4.   

    哦,,错了,应该是这样..with TFileStream.create(FileName,fmOpenRead) do
      begin
        SetLength(Result,size);
        Read(PChar(Result)^, size);  这句改成这样才行.
      end
      

  5.   

    halfdream(哈欠) 兄的方法是正确的
      

  6.   

    function BlobContentToString(const FileName:string):string;SetLength(Result,Size);
    with TFileStream.create(FileName,fmOpenRead) do
      Read(Result[1], size);
      

  7.   

    我是想把任何类型的文件读到流里面Read(Result[1], size);
    Read(PChar(Result)^, size); 这2个都能实现我想要实现的结果我现在不明白第1句为什么这样写。。
    请大家帮我解释一下。。
      

  8.   

    Read 的第一个参数是var类型,其实是一个指针,而Result[1]和PChar(Result)^的地址相同
    !!! 另外 TFileStream 使用完需要 Free;with TFileStream.create(FileName,fmOpenRead) do
      try
        SetLength(Result,size);
        Read(Result[1], size);
      finally
        Free;
      end;