Domanda

Ho il seguente codice che non riesce sempre con un "Estratto errore":

  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;

Tuttavia, ho sempre arrivare quell'errore quando si cerca di comprimere. Tutte le idee su quello che sto facendo male qui?

È stato utile?

Soluzione

Credo che bisogna dire è che tipo di JclCompressArchive per creare, come ad esempio dare arch := TJcl7zCompressArchive.Create... invece di JclCompressArchive.Create ().

Se si guarda alla sezione "Gerarchia delle classi" di 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 ...

Aggiorna
Credo che il modo corretto di utilizzare StackOverflow sarebbe stata quella di aggiungere una nuova domanda, dal momento che dopo l'aggiornamento, è una questione del tutto diversa.

Non so il motivo per cui si sta gettando a TJclCompressArchive a AddFile () e comprimere (), sembra funzionare per me senza i calchi

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top