¿Por qué aparece un “error abstracto” al llamar TJclCompressArchive.Compress?
-
21-09-2019 - |
Pregunta
Tengo el siguiente código que siempre falla con un "Error Resumen":
arch := TJclCompressArchive.Create(GetDesktop + 'Support.7z');
try
with arch do
begin
if FindFirst('*.log', faAnyFile, sr) = 0 then
begin
repeat
AddFile(ExtractFileName(sr.Name),sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
Compress; //this line throws the error
end;
finally
arch.free;
end;
Sin embargo, siempre me sale ese error al intentar comprimir. ¿Alguna idea sobre lo que estoy haciendo mal aquí?
Solución
Creo que usted tiene que decirle qué tipo de JclCompressArchive para crear, como por ejemplo darle arch := TJcl7zCompressArchive.Create...
en lugar de JclCompressArchive.Create ().
Si nos fijamos en la sección "Jerarquía de la clase" de JclCompression.pas:
TJclCompressionArchive
|
|-- TJclCompressArchive
| |
| |-- TJclSevenzipCompressArchive
| |
| |-- TJclZipCompressArchive handled by sevenzip ...
| |-- TJclBZ2CompressArchive handled by sevenzip ...
| |-- TJcl7zCompressArchive handled by sevenzip ...
| |-- TJclTarCompressArchive handled by sevenzip ...
| |-- TJclGZipCompressArchive handled by sevenzip ...
| |-- TJclXzCompressArchive handled by sevenzip ...
Actualizar
Creo que la forma correcta de utilizar Stackoverflow habría sido añadir una nueva pregunta, ya que después de la actualización, que es una cuestión completamente diferente.
No sé por qué estás echando a TJclCompressArchive a AddFile () y comprimir (), parece que funciona para mí sin los moldes
const
FILENAME = 'Support.7z';
var
archiveclass: TJCLUpdateArchiveClass;
arch: TJclUpdateArchive;
sr: TSearchRec;
begin
archiveclass := GetArchiveFormats.FindUpdateFormat(FILENAME);
if not Assigned(archiveclass) then
raise Exception.Create('Could not determine the Format of ' + FILENAME);
arch := archiveclass.Create(FILENAME);
try
// if FileExists(FILENAME) then // if you want to add any new files,
// arch.ListFiles; // in addition to what is already there
if FindFirst('*.pas', faAnyFile, sr) = 0 then
begin
repeat
arch.AddFile(ExtractFileName(sr.Name),sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
arch.Compress;
finally
arch.free;
end;
end;