比如读写字符串,数字等。200分送。最好给例子。

解决方案 »

  1.   

    使用TFileStream,按字节数读————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    能给例子么,我试了一下,写是能写,读却读不出来。
    我的例子:
      try
        fs:=TFileStream.Create('c:\gggg.dbf',fmOpenWrite);
        fs.Seek(0,2);
        i:='bizzard';
        fs.Write(i,20);    //fs.ReadBuffer(i,sizeof(short));
        ShowMessage('hh'+i+'hh');
      finally
        fs.Free;
      

  3.   

    就是没有书啊,有电子书么?发个给俺把,[email protected],谢谢你了。
      

  4.   

    使用使用TFileStream类。我有《Delphi 开发人员指南》的源代码,其中第12章是文件处理。
    我把这一章的代码给你发过去,你自己看吧。
      

  5.   

    procedure LoadParParams;//读文件
    var
        h:file;
    begin
        AssignFile(h,CurrExePath+'aaa.par');
        Reset(h,1);
        BlockRead(h, cfg, sizeof(cfg));
        BlockRead(h, total_number, sizeof(Integer));
        ......
        CloseFile(h);
    end;procedure SaveParParams;//写文件
    var
        h:file;
    begin
        AssignFile(h,CurrExePath+'aaa.par');
        Rewrite(h,1);
        BlockWrite(h, cfg, sizeof(cfg));
        BlockWrite(h, total_number, sizeof(Integer));
        ......
        CloseFile(h);
    end;
      

  6.   

    这是我写的读 qq 号码的过程:procedure TF_qqlist.readqq(qqpath:string);
    var   oicqfile:file;
          buffer:array[0..255] of byte ;
          j,i,usercount,no_len,old_pos:integer;
          oicqno:string;begin
      // i:=1;
       listbox1.Items.Clear ;
       try
         assignfile(oicqfile,qqpath);
         reset(oicqfile,1);
        // size := FileSize(oicqfile);     seek(oicqfile,0);
         blockread(oicqfile,buffer,9,j);
         usercount:= buffer[8];
         edit1.text:=inttostr(usercount);
         seek(oicqfile,12);
         blockread(oicqfile,buffer,1,j);
         //showmessage(inttostr(buffer[0]));
         no_len:=buffer[0]; //第一行长度     old_pos:=12;
         while not eof(oicqfile) do
         begin
          seek(oicqfile,old_pos + 4);
          blockread(oicqfile,buffer,no_len,j);
          oicqno:='';
          for i:=0 to no_len-1 do
            oicqno:= oicqno + chr(buffer[i]);
          listbox1.Items.Add(oicqno);      old_pos:= old_pos + 4 + no_len;
          seek(oicqfile,old_pos);
          blockread(oicqfile,buffer,1,j);
    //     showmessage(inttostr(buffer[0]));
          no_len:=buffer[0];
         end;
        finally
         closefile(oicqfile);
        end;end;
      

  7.   

    var
      s: TMemoryStream;
      StrDT: TDateTime;
      StrAll: LongInt;
    begin
      TeThemeMemo1.Clear;
      if FileExists(ExtractFilePath(Application.ExeName)+'\Record.dat') then
        begin
          s:= TMemoryStream.Create;
          try
            s.LoadFromFile(ExtractFilePath(Application.ExeName)+'\Record.dat');
            s.Position:= 0;
            //showmessage(IntToStr(S.Size));
            while s.Position < s.Size do
            begin
              s.Read(StrDT, SizeOf(TDateTime));
              s.Read(StrAll, SizeOf(LongInt));
              TeThemeMemo1.Lines.Add('<'+ datetimetostr(strDT)+'> 结算 --> 共计  '+IntToStr(StrAll)+' 分钟');
            end;
          finally
            s.Free;
          end;
        end;
    end;
      

  8.   

    var i:string;
        len:integer;
    try
        fs:=TFileStream.Create('c:\gggg.dbf',fmOpenWrite);
        fs.Seek(0,2);
        i:='bizzard';
        len:=sizeof(i));
        fs.Write(i[1],len);
        fs.position:=0;
          
        Setlength(i,len+1);
        fs.Read(i[1],len);
        i[len+1]:=#0;
        ShowMessage('hh'+i+'hh');
      finally
        fs.Free;
      

  9.   

    procedure TfrmMain.btnReadClick(Sender: TObject);
    var
      fs:TFileStream;
      stream:TStream;
      i:short;
    begin
      try
        fs:=TFileStream.Create('c:\&Auml;ê&Ecirc;&Otilde;&Egrave;&euml;.dbf',fmOpenWrite);
        fs.Position:=0;
        fs.Read(i,sizeof(short));
        ShowMessage(IntToStr(ord(i)));
      finally
        fs.Destroy;
      end;
    end;
    这是我的一段代码,怎么显示64,我用ultraedit打开,第一个字节是0x30,应该显示48啊。
      

  10.   

    //如果是一个字节
    procedure TfrmMain.btnReadClick(Sender: TObject);
    var
      fs:TFileStream;
      stream:TStream;
      i:integer;
    begin
      try
        fs:=TFileStream.Create('c:\&Auml;ê&Ecirc;&Otilde;&Egrave;&euml;.dbf',fmOpenWrite);
    //    fs.Position:=0;
        fs.Read(i,1);
        ShowMessage(IntToStr(i));
      finally
        fs.Destroy;
      end;
    end;