Mega Code Archive

 
Categories / Delphi / ADO Database
 

How to access Paradox tables on CD or read only drives

Title: How to access Paradox tables on CD or read-only drives {1. Starting with a blank project add the following components:} TEdit, TButton and TDatabase. {2. In the OnClick event for the button use the following code:} procedure TForm1.Button1Click(Sender: TObject); begin if ChkPath then Check(DbiAcqPersistTableLock(Database1.Handle, 'PARADOX.DRO', 'PARADOX')); end; {3. The ChkPath function is a user defined method of the form. It will simply check the path entered in the Edit box and make sure it exists. Here is the function:} function TForm1.ChkPath: Boolean; var s: array[0..100] of char; begin if DirectoryExists(Edit1.Text) then begin DataBase1.DatabaseName := 'TempDB'; DataBase1.DriverName := 'Standard'; DataBase1.LoginPrompt := False; DataBase1.Connected := False; DataBase1.Params.Add('Path=' + Edit1.Text); DataBase1.Connected := True; Result := True; end else begin StrPCopy(s, 'Directory : ' + Edit1.Text + ' Does Not Exist'); Application.MessageBox(s, 'Error!', MB_ICONSTOP); Result := False; end; end; { Note: Don't forget to put the function header in the public section of the form.} {4. There is one more thing you need to add before compiling, in the Uses statement at the top of the unit add the following units:} Delphi 1.0: FileCtrl, DbiProcs, DbiTypes, DbiErrs.Delphi 2.0: FileCtrl, BDE {When you have compiled and executed the utility program, it will create two files in the directory you specified. The two files created are: PDOXUSRS.LCK and PARADOX.LCK.} {Note: The PARADOX.LCK file is only necessary when accessing Paradox for DOS tables so you can delete it.} {5. The only thing left for you to do is copy the remaining file (PDOXUSRS.LCK) to the CD-ROM image. Of course your tables will be Read-Only.} {Note: If you want to clean up this utility for future use, you can change the text property of the Edit box to be some default directory and change the Caption property of the Button to be something more meaningful.} {Here is the final version of the code:} unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DB, StdCtrls, FileCtrl, {$IFDEF WIN32} BDE; {$ELSE} DbiProcs, DbiTypes, DbiErrs; {$ENDIF } type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Database1: TDatabase; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } function ChkPath: Boolean; end; var Form1: TForm1; implementation {$R *.DFM} function TForm1.ChkPath: Boolean; var s: array[0..100] of char; begin if DirectoryExists(Edit1.Text) then begin DataBase1.DatabaseName := 'TempDB'; DataBase1.DriverName := 'Standard'; DataBase1.LoginPrompt := False; DataBase1.Connected := False; DataBase1.Params.Add('Path=' + Edit1.Text); DataBase1.Connected := True; Result := True; end else begin StrPCopy(s, 'Directory : ' + Edit1.Text + ' Does Not Exist'); Application.MessageBox(s, 'Error!', MB_ICONSTOP); Result := False; end; end; procedure TForm1.Button1Click(Sender: TObject); begin if ChkPath then Check(DbiAcqPersistTableLock(Database1.Handle, 'PARADOX.DRO', 'PARADOX')); end; end.