A: Note: The reason that you want to be able to lock a directory is that if you want to place data files on to a CD and read them there, you need a directory lock so that the BDE knows to not try to write to that directory. This makes the files read only, but it works.
unit Dirlocku;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, DbiTypes, DbiProcs, DbiErrs, DB, StdCtrls, Buttons,
FileCtrl;
type
TForm1 = class(TForm)
Database1: TDatabase;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
function ChkPath : Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.ChkPath : Boolean;
var
s : String;
begin
If DirectoryExists(Edit1.Text) then
with DataBase1 do begin
Connected := False;
Params.Add('Path=' + Edit1.Text);
Connected := TRUE;
Result := TRUE;
end
else begin
s := 'Directory : ' + Edit1.text + ' Does Not Exist';
Application.MessageBox(pChar(s), 'Error!', MB_ICONSTOP);
Result := FALSE;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if ChkPath then
check(DBIRelPersistTableLock(Database1.Handle, 'PARADOX.DRO',
'PARADOX'));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if ChkPath then
check(DBIAcqPersistTableLock(Database1.Handle, 'PARADOX.DRO','PARADOX'));
end;
end.