You read it back the same way you write it, in reverse:
// Write the comment
iZipFile.FileComment[Index] := 'This is a zip file comment';
// Read it back
sComment := iZipFile.FileComment[Index];
WriteLn(sComment); // Outputs "This is a zip file comment"
Index
would match the index of the individual file within the zip archive. In other words, the first file would be at index 0, the second at index 1, etc., wit the last being at index FileCount - 1
.
Here's a working example. I created a dummy zip file named Test.zip
containing a few old .png files I've used in answers here (as seen in the image below):
I then used the below code to add comments to each file and read them back, writing them to the console:
program Project1;
{$APPTYPE CONSOLE}
uses
System.SysUtils, System.Zip;
var
Zip: TZipFile;
i: Integer;
begin
Zip := TZipFile.Create;
Zip.Open('D:\TempFiles\Test.zip', zmReadWrite);
for i := 0 to Zip.FileCount - 1 do
Zip.FileComment[i] := Format('This is file %d', [i]);
Zip.Free; // Flushes changes to disk automatically
// Create a new instance, just to make it clear.
Zip := TZipFile.Create;
Zip.Open('D:\TempFiles\Test.zip', zmReadWrite);
for i := 0 to Zip.FileCount - 1 do
WriteLn(Zip.FileNames[i] + ':'#9 + Zip.FileComment[i]);
Zip.Free;
ReadLn;
end.
Here's the output it produced:
Here's the zip file comments it added, as displayed in 7Zip: