Delphi DLL
Delphi DLL
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 DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ZipEntry, Zip;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
zip: HCkZip;
entry: HCkZipEntry;
entryId: Integer;
entry2: HCkZipEntry;
begin
success := False;
success := False;
// Open an existing ZIP archive.
zip := CkZip_Create();
success := CkZip_OpenZip(zip,'example.zip');
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
// Retrieve the first entry in the ZIP archive.
entry := CkZipEntry_Create();
success := CkZip_EntryAt(zip,0,entry);
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
Memo1.Lines.Add('Original entry:');
Memo1.Lines.Add(' FileName: ' + CkZipEntry__fileName(entry));
Memo1.Lines.Add(' EntryID: ' + IntToStr(CkZipEntry_getEntryID(entry)));
Memo1.Lines.Add('');
// Save the EntryID for later use.
entryId := CkZipEntry_getEntryID(entry);
// Create another ZipEntry object.
entry2 := CkZipEntry_Create();
// Retrieve the same entry using EntryById.
success := CkZip_EntryById(zip,entryId,entry2);
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
Memo1.Lines.Add('Entry retrieved by EntryID:');
Memo1.Lines.Add(' FileName: ' + CkZipEntry__fileName(entry2));
Memo1.Lines.Add(' EntryID: ' + IntToStr(CkZipEntry_getEntryID(entry2)));
Memo1.Lines.Add('');
// The filenames and EntryID values should match.
CkZip_CloseZip(zip);
Memo1.Lines.Add('Done.');
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
CkZipEntry_Dispose(entry2);
end;