Pergunta

Eu tenho o seguinte código que sempre falha com um "erro abstrato":

  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;

No entanto, sempre recebo esse erro ao tentar comprimir. Alguma idéia do que estou fazendo de errado aqui?

Foi útil?

Solução

Eu acredito que você tem que dizer que tipo de jclcompressarchive de criar, como dar arch := TJcl7zCompressArchive.Create... em vez de jclCompressarchive.create ().

Se você olhar para a seção "Hierarquia de classe" do 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 ...

Atualizar
Eu acho que a maneira correta de usar o StackOverflow seria adicionar uma nova pergunta, pois após a atualização, é uma pergunta completamente diferente.

Não sei por que você está lançando para TJClCompressarchive para addfile () e compact (), parece funcionar para mim sem os elencos

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;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top