The Unofficial Newsletter of Delphi Users - by Robert Vivrette


Sorting Out Lock Files Once and For All!

by Matt Hamilton - MHamilton@bunge.com.au

Every once in a while I've had the old "Lock file has grown too large" or "Directory is controlled by another .net file" errors. Very frustrating. So I did some reading, and came up with a solution.

The Delphi help file says that you should use the Session.NetFileDir and Session.PrivateDir properties to control where paradox puts its lock files. It recommends that, for network applications, NetFileDir be the same directory as the executable, and that PrivateDir be a local directory.

This is incorrect in two ways: Firstly, if you are running your application from a network drive, say

. . . and the data itself is stored in a subdirectory . . . then each user might not have access to "F\MyApp" - you wouldn't want them deleting the exe, for example.

Thus, the NetFileDir should really sit in the database directory "F:\MyApp\MyData\", to ensure that the users have full access to it.

Secondly, if the user runs more than one Paradox application concurrently, and both use the same local directory, say

. . . then they will get a "Directory is controlled by another .net file" error - since a lock file already exists there. So each application should have its own local directory for keeping private lock files.

Well, here's my solution. First, put this in your Datamodule's OnCreate event:

Next, use this code in the datamodule's OnDestroy event: There you have it! No more lock file problems, even if you're running more than one Paradox app off the network!