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
with rForm.Lista do
if rForm.saveDialog1.Execute then
begin
ItemCount := 0;
SubCount := 0;
MySignature := 'txt';
F := TFileStream.Create(rForm.saveDialog1.FileName, fmCreate or fmOpenWrite);
F.Write(MySignature, SizeOf(MySignature));
if Items.Count = 0 then
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
if SubItems.Count = 0 then
SubCount := 0
else
begin
SubCount := Subitems.Count;
F.Write(SubCount, SizeOf(SubCount));
IdxImage := ImageIndex;
F.Write(IdxImage, SizeOf(IdxImage));
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
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.