//你说的是它?我的怎么可以执行呢procedure TForm1.Button1Click(Sender: TObject);
var
  iFileHandle: Integer;
  iFileLength: Integer;
  iBytesRead: Integer;
  Buffer: PChar;
  i: Integer;
begin
  if OpenDialog1.Execute then
  begin
    try
      iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
      iFileLength := FileSeek(iFileHandle,0,2);
      FileSeek(iFileHandle,0,0);
      Buffer := PChar(AllocMem(iFileLength + 1));
      iBytesRead := FileRead(iFileHandle, Buffer^, iFileLength);      FileClose(iFileHandle);
      for i := 0 to iBytesRead-1 do
      begin
        StringGrid1.RowCount := StringGrid1.RowCount + 1;
        StringGrid1.Cells[1,i+1] := Buffer[i];
        StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer[i]));
      end;
    finally
      FreeMem(Buffer);
    end;
  end;
end;

解决方案 »

  1.   

    过不去你就改一下了,
    下面是我改过的。
    var
      BackupName: string;
      FileHandle: Integer;
      StringLen: Integer;
      X: Integer;
      Y: Integer;
    begin
      if SaveDialog1.Execute then
      begin
        if FileExists(SaveDialog1.FileName) then
        begin
          BackupName := ExtractFileName(SaveDialog1.FileName);
          BackupName := ChangeFileExt(BackupName, '.BAK');
          if not RenameFile(SaveDialog1.FileName, BackupName) then        raise Exception.Create('Unable to create backup file.');
        end;
        FileHandle := FileCreate(SaveDialog1.FileName);
        { Write out the number of rows and columns in the grid. }
        FileWrite(FileHandle,
          StringGrid1.ColCount, SizeOf(StringGrid1.ColCount));
        FileWrite(FileHandle, 
          StringGrid1.RowCount, SizeOf(StringGrid1.RowCount));
        for X := 0 to StringGrid1.ColCount -1 do
        begin      for Y := 0 to StringGrid1.RowCount -1 do
          begin
            { Write out the length of each string, followed by the string itself. }
            StringLen := Length(StringGrid1.Cells[X,Y]);
            FileWrite(FileHandle, StringLen, SizeOf(StringLen));
            FileWrite(FileHandle, PChar(StringGrid1.Cells[X,Y])^,Length(StringGrid1.Cells[X,Y]));
          end;
        end;
        FileClose(FileHandle);
      end;
    end;
      

  2.   

    netlib(河外孤星)兄:
    能不能写出对应的读代码,可以给你加分。
      

  3.   

    delphi中的指针实在用不好,关键是如何将缓存中的数据分开?