home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
- PRODUCT : Delphi NUMBER : 2711
- VERSION : All
- OS : Windows
- DATE : July 14, 1995 PAGE : 1/3
-
- TITLE : How to Circumvent the "index not found" Exception.
-
-
-
-
- Q: How do I open a dBASE table without the required MDX file?
- I keep getting an "Index not found..." exception.
-
- A: When you create a dBASE table with a production index (MDX), a
- special byte is set in the header of the DBF file. When you
- subsequently attempt to re-open the table, the dBASE driver
- will read that special byte, and if it is set, it will also
- attempt to open the MDX file. When the MDX file cannot be
- opened, an exception is raised.
-
- To work around this problem, you need to reset the byte (byte
- 28 decimal) in the DBF file that causes the MDX dependency
- to zero.
-
- The following unit is a simple example of how to handle the
- exeption on the table open, reset the byte in the DBF file,
- and re-open the table.
-
- unit Fixit;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
- Controls, Forms, Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids;
-
- type
- TForm1 = class(TForm)
- Table1: TTable;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
-
-
-
-
-
-
-
-
-
-
-
-
-
- PRODUCT : Delphi NUMBER : 2711
- VERSION : All
- OS : Windows
- DATE : July 14, 1995 PAGE : 2/3
-
- TITLE : How to Circumvent the "index not found" Exception.
-
-
-
-
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- const
- TheTableDir = 'c:\temp\';
- TheTableName = 'animals.dbf';
-
- procedure RemoveMDXByte(dbFile: String);
- { This procedure accepts a DBF file as a parameter. It will patch}
- { the DBF header, so that it no longer requires the MDX file }
- const
- Value: Byte = 0;
- var
- F: File of byte;
- begin
- AssignFile(F, dbFile);
- Reset(F);
- Seek(F, 28);
- Write(F, Value);
- CloseFile(F);
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- { This procedure is called in response to a button click. It }
- { attempts to open a table, and, if it can't find the .MDX file, }
- { it patches the DBF file and re-execute the procedure to }
- { re-open the table without the MDX }
- begin
- try
- { set the directory for the table }
- Table1.DatabaseName := TheTableDir;
- { set the table name }
- Table1.TableName := TheTableName;
- { attempt to open the table }
- Table1.Open;
-
-
-
-
-
-
-
-
-
-
-
-
-
- PRODUCT : Delphi NUMBER : 2711
- VERSION : All
- OS : Windows
- DATE : July 14, 1995 PAGE : 3/3
-
- TITLE : How to Circumvent the "index not found" Exception.
-
-
-
-
- except
- on E:EDBEngineError do
- { The following message indicates the MDX wasn't found: }
- if Pos('Index does not exist. File', E.Message)>0 then begin
- { Tell user what's going on. }
- MessageDlg('MDX file not found. Attempting to open
- without index.', mtWarning, [mbOk], 0);
- { remove the MDX byte from the table header }
- RemoveMDXByte(TheTableDir + TheTableName);
- { Send the button a message to make it think it was }
- { pressed again. Doing so will cause this procedure to }
- { execute again, and the table will be opened without }
- { the MDX }
- PostMessage(Button1.Handle, cn_Command, bn_Clicked, 0);
- end;
- end;
- end;
-
- end.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- DISCLAIMER: You have the right to use this technical information
- subject to the terms of the No-Nonsense License Statement that
- you received with the Borland product to which this information
- pertains.
-