Почему я получаю «абстрактную ошибку» при вызове TJclCompressArchive.Compress? - PullRequest
1 голос
/ 24 декабря 2009

У меня есть следующий код, который всегда завершается с «Абстрактной ошибкой»:

  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;

Тем не менее, я всегда получаю эту ошибку при попытке сжать. Есть идеи о том, что я здесь делаю не так?

1 Ответ

4 голосов
/ 24 декабря 2009

Я полагаю, вы должны указать, какой тип JclCompressArchive создать, например, дать ему arch := TJcl7zCompressArchive.Create... вместо JclCompressArchive.Create ().

Если вы посмотрите на раздел «Иерархия классов» в 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 ...

Обновление
Я думаю, что правильным способом использования StackOverflow было бы добавить новый вопрос, поскольку после обновления это совершенно другой вопрос.

Я не знаю, почему вы приводите TJclCompressArchive в AddFile () и Compress (), мне кажется, это работает без приведения

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;
...