لماذا أحصل على "خطأ تجريدي" عند استدعاء tjclcompressarchive.com؟

StackOverflow https://stackoverflow.com/questions/1955338

سؤال

لدي الرمز التالي الذي يفشل دائمًا مع "خطأ تجريدي":

  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;

ومع ذلك ، أحصل دائمًا على هذا الخطأ عند محاولة الضغط. أي أفكار حول ما أفعله خطأ هنا؟

هل كانت مفيدة؟

المحلول

أعتقد أنك يجب أن تخبرها أي نوع من 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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top