TZipFile with Password Encryption (Part 2)

The first part of this article describes a simple but limited way to read password encrypted zip files with a derived TZipFile class. The limitations are

  1. it can only read but not create encrypted zip files
  2. the size of the zip files is limited by the available memory

While this solution does the job in the scenario it was built for, I cannot say that I was really satisfied with that. So I investigated ways how these limitations can be overcome.

It turned out that it was not that easy as I anticipated. Continue reading “TZipFile with Password Encryption (Part 2)”

TZipFile with Password Encryption

As some of you might already know, Delphi (at least since XE2) comes with a built-in TZipFile class for reading and writing zip files. It is a rather basic class with only limited functionality, but this might just be enough for quite a couple of day-to-day tasks.

During a recent migration of a project from Delphi 7 to Delphi 10.1 Berlin I was facing the decision to either fix the current zip implementation (based on external DLLs) or switch to the stock implementation using TZipFile. The second option would also have the advantage of getting rid of distributing the DLLs. So I headed for that one.

Well, as always when you think you have found the right solution and start coding – reality steps in. Some of the zip files we had to read were password protected. Unfortunately TZipFile doesn’t support password encryption out of the box. Continue reading “TZipFile with Password Encryption”

Dataset Enumerator Reloaded

A couple of years ago I wrote a two-part article about a dataset enumerator: A Magical Gathering – Part 1 and Part 2. Well, things evolved a bit since then and I wondered how one would implement something similar given the current features of Delphi. Actually I am following here a suggestion from commenter Alan Clark. Continue reading “Dataset Enumerator Reloaded”

Conditionally using FastMM avoiding IFDEFs in the DPR

This a follow up of my previous post Conditional Uses Clause Considered Harmful, showing another real world use case of the technique described there.

Let’s assume we want to use FastMM with Full Debug Mode in a project to track down some errors in DEBUG mode. This requires us to include the FastMM4 unit as the first entry in the uses clause of the project DPR.

Now let’s also assume, we don’t want to use that FastMM unit in the RELEASE configuration – and – NO! – we don’t want to use an IFDEF inside the DPR, as the IDE tends to mess up with such things pretty often.

Using a unit alias like

  • FastMM4=System

solves this in a simple and elegant way.

 

Conditional Uses Clause Considered Harmful

Everyone writing Delphi code that is meant to compile under different Delphi versions has come to the point where conditional compilation seems unavoidable. Ever so often it tends to creep into the uses clauses as well. So, what can we do when units like System.Actions and System.ImageList simple aren’t available in older Delphi versions?

Solution 1: Add an empty unit with the proper name to the project. You might end up with a collection of empty units in your version control system. But hey, it does the job.

Solution 2: Add a unit alias to the project, mapping the unknown units to existing ones you are using anyway. For the two units mentioned above some good candidates are:

  • System.Actions=Vcl.ActnList (for versions below XE3)
  • System.ImageList=Vcl.ImgList (for versions below XE8)

There are a couple of tools that fiddle around with your uses clause from time to time. They will thank you for getting rid of conditions there.