Programación General > Delphi

 Ficheros

<< < (2/2)

JMAlonso:
lo que necesito es esto ,es decir escribir, leer etc. de un fichero, que viene en la ayuda de delphi pero tiene un error y no se como arreglarlo.


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, StringGrid1.Cells[X,Y] ,Length(StringGrid1.Cells[X,Y]));
      end;
    end;
    FileClose(FileHandle);
  end;


el error esta en la linea en negrita, queriendo escribir en el fichero lo que contiene
la celda del grid y su longitud, pero da error.


Saludos.


Saludos.

Amilius:
:blink:
Eso es sencillísimo...  :D

StringLen := Length(StringGrid1.Cells[X,Y]);
FileWrite(FileHandle, StringLen, SizeOf(StringLen));
FileWrite(FileHandle, StringGrid1.Cells[X,Y] ,StringLen);

Navegación

[0] Índice de Mensajes

[*] Página Anterior

Ir a la versión completa