Ver Mensaje Individual
  #1  
Antiguo 15-11-2014
Avatar de danielmj
danielmj danielmj is offline
Miembro
 
Registrado: jun 2011
Posts: 383
Reputación: 13
danielmj Va por buen camino
Guardar ListView como Texto Plano

Hola,

Sigo con la lista de otro post anterior a este, solo que esta vez el problema es otro. Intento guardar el contenido de la lista en un archivo de texto plano, buscando información por internet, encontre este código, que imagino ya habreis visto antes:

Código Delphi [-]
procedure guardarListViewFichero (AListView: TListView; sFileName: string);
var
  idxItem, idxSub, IdxImage: Integer;
  F: TFileStream;
  pText: PChar;
  sText: string;
  W, ItemCount, SubCount: Word;
  MySignature: array [0..2] of Char;

begin
  // Inicio
  with rForm.Lista do
  if rForm.saveDialog1.Execute then
  begin
    ItemCount := 0;
    SubCount  := 0;
    //****
    MySignature := 'txt';
    //  ListViewFile
    F := TFileStream.Create(rForm.saveDialog1.FileName, fmCreate or fmOpenWrite);
    F.Write(MySignature, SizeOf(MySignature));

    if Items.Count = 0 then
      // List is empty
      ItemCount := 0
    else
      ItemCount := Items.Count;
      F.Write(ItemCount, SizeOf(ItemCount));

    if Items.Count > 0 then
    begin
      for idxItem := 1 to ItemCount do
      begin
        with Items[idxItem - 1] do
        begin
          // Guardamos los SubItems
          if SubItems.Count = 0 then
            SubCount := 0
          else
          begin
          SubCount := Subitems.Count;
          F.Write(SubCount, SizeOf(SubCount));
          // Guardamos el Index
          IdxImage := ImageIndex;
          F.Write(IdxImage, SizeOf(IdxImage));
          // Guardamos la Caption
          sText := Caption;
          w     := Length(sText);
          pText := StrAlloc(Length(sText) + 1);
          StrPLCopy(pText, sText, Length(sText));
          F.Write(w, SizeOf(w));
          F.Write(pText^, w);
          StrDispose(pText);
          end;
          if SubCount > 0 then
          begin
            for idxSub := 0 to SubItems.Count - 1 do
            begin
              // Guardamos los Items y SubItems
              sText := SubItems[idxSub];
              w     := Length(sText);
              pText := StrAlloc(Length(sText) + 1);
              StrPLCopy(pText, sText, Length(sText));
              F.Write(w, SizeOf(w));
              F.Write(pText^, w);
              StrDispose(pText);
            end;
          end;
        end;
      end;
    end;
    F.Free;
  end;

end;

En la opcion "crear informe" del popup menú tengo esto:
Código Delphi [-]
procedure TrForm.Crearinforme1Click(Sender: TObject);
begin
    guardarListViewFichero(Lista, SaveDialog1.FileName);
end;

Aparentemente todo va bien, quiero decir que no da error en tiempo de compilación, pero cuando intento crear el informe, me tira un error de "stack overflow" como si hubiera desbordamiento de pila, y la verdad, no sé donde está el error (me refiero en el código)

¿alguna idea? Gracias y un saludo.
__________________
La juventud pasa, la inmadurez se supera, la ignorancia se cura con la educación, y la embriaguez con la sobriedad, pero la estupidez dura para siempre. Aristofanes.
Responder Con Cita