Stéphane Wierzbicki 45 Posted August 31, 2019 (edited) Hello, Anyone knows how I can delete an archive Item using TZipFile class ? I found a TZipFileHelper class helper on the net. It is useless since we cannot access TZipFile private members anymore. procedure TZipFileHelper.Delete(FileName: string); var i, j: Integer; StartOffset, EndOffset, Size: UInt32; Header: TZipHeader; Buf: TBytes; begin i := IndexOf(FileName); if i <> -1 then begin // Find extents for existing file in the file stream StartOffset := Self.FFiles[i].LocalHeaderOffset; EndOffset := Self.FEndFileData; for j := 0 to Self.FFiles.Count - 1 do begin if (Self.FFiles[j].LocalHeaderOffset > StartOffset) and (Self.FFiles[j].LocalHeaderOffset <= EndOffset) then EndOffset := Self.FFiles[j].LocalHeaderOffset; end; Size := EndOffset - StartOffset; // Update central directory header data Self.FFiles.Delete(i); for j := 0 to Self.FFiles.Count - 1 do begin Header := Self.FFiles[j]; if Header.LocalHeaderOffset > StartOffset then begin Header.LocalHeaderOffset := Header.LocalHeaderOffset - Size; Self.FFiles[j] := Header; end; end; // Remove existing file stream SetLength(Buf, Self.FEndFileData - EndOffset); Self.FStream.Position := EndOffset; if Length(Buf) > 0 then Self.FStream.Read(Buf[0], Length(Buf)); Self.FStream.Size := StartOffset; if Length(Buf) > 0 then Self.FStream.Write(Buf[0], Length(Buf)); Self.FEndFileData := Self.FStream.Position; end; end; ps: I'm using Delphi RIO Edited August 31, 2019 by Stéphane Wierzbicki Share this post Link to post
FredS 138 Posted August 31, 2019 5 hours ago, Stéphane Wierzbicki said: access TZipFile private members WITH is your friend: // from https://stackoverflow.com procedure TSomeClassHelper.CheckAccessToPrivate; begin With Self do begin // access via with works FInt :=1; SomeMethod; end; end; // Declared in another unit as: type TSomeClass = class private FInt : integer; procedure SomeMethod; end; Share this post Link to post
Stéphane Wierzbicki 45 Posted August 31, 2019 2 hours ago, FredS said: WITH is your friend: Thank you. That is clearly a bug ! I'm surprised EMB did not fixed it!. Share this post Link to post
Remy Lebeau 1436 Posted September 2, 2019 (edited) On 8/31/2019 at 10:37 AM, Stéphane Wierzbicki said: That is clearly a bug ! I'm surprised EMB did not fixed it!. They are aware of it. Just as they have already fixed other access issues related to helpers, it is likely only a matter of time before they do fix this one too. Edited September 2, 2019 by Remy Lebeau Share this post Link to post