Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
Find a ZIP Entry by EntryID Using EntryById
See more Zip Examples
This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.
Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.
This is useful when:
- An application stores EntryID values for later use
- ZIP entries need to be retrieved without searching by filename
- Multiple entries may have similar names or paths
The example:
- Opens a ZIP archive
-
Retrieves an entry using
EntryAt -
Saves the entry's
EntryID -
Uses
EntryByIdto retrieve the same entry later
Chilkat Delphi ActiveX Downloads
var
success: Integer;
zip: TChilkatZip;
entry: TChilkatZipEntry;
entryId: Integer;
entry2: TChilkatZipEntry;
begin
success := 0;
// Open an existing ZIP archive.
zip := TChilkatZip.Create(Self);
success := zip.OpenZip('example.zip');
if (success = 0) then
begin
Memo1.Lines.Add(zip.LastErrorText);
Exit;
end;
// Retrieve the first entry in the ZIP archive.
entry := TChilkatZipEntry.Create(Self);
success := zip.EntryAt(0,entry.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(zip.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Original entry:');
Memo1.Lines.Add(' FileName: ' + entry.FileName);
Memo1.Lines.Add(' EntryID: ' + IntToStr(entry.EntryID));
Memo1.Lines.Add('');
// Save the EntryID for later use.
entryId := entry.EntryID;
// Create another ZipEntry object.
entry2 := TChilkatZipEntry.Create(Self);
// Retrieve the same entry using EntryById.
success := zip.EntryById(entryId,entry2.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(zip.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Entry retrieved by EntryID:');
Memo1.Lines.Add(' FileName: ' + entry2.FileName);
Memo1.Lines.Add(' EntryID: ' + IntToStr(entry2.EntryID));
Memo1.Lines.Add('');
// The filenames and EntryID values should match.
zip.CloseZip();
Memo1.Lines.Add('Done.');