Solved

IndexFile missing Dbase

Posted on 1998-05-19
1
434 Views
Last Modified: 2013-11-24
Hi,

How can I open or add indexes to a Dbase IV table when the Indexfile (*.MDX)
is missing. With Database desktop it is possible to open such a table, so I
expect that there is BDE function to do this. I want to make a tool that
opens such tables and restores the indexes.

I tried with Table.open, dbiopentable and Table.addindex but I get always
the message index does not exist.

I am using Delphi 1.0

All help is appreciated

Regards Didier,
0
Comment
Question by:Didier
1 Comment
 

Accepted Solution

by:
jhunt earned 70 total points
ID: 1346210
What you basicly have to do is:
Examine if byte 28 in the header of the DBase file is set to 1. If so the BDE expects a production index. If the index file is not there then you will have to change byte 28 of the header from 1 to 0.

This is what does the trick:
TDBFHeader = record
 ID: byte;
 LastUpdate: array[1..3] of byte;
 LastRec: integer;
 DataOffset: word;
 RecordSize: word;
 Filler1: array[1..16] of byte;
 StructIDX: boolean;
 Filler2: array[1..3] of byte;
end;

in the beforeopen event of your table:
procedure TCodeTable.DoBeforeOpen;
var      filename, extension: string;
      DBF: TFileStream; Dbase: TDatabase;
      Header: TDBFHeader;
begin
 DBase := Session.FindDatabase ( Databasename );
 extension := ExtractFileExt(TableName);
 if not DBase.IsSQLBased and
     ( (CompareText(extension, '.DBF') = 0) or (TableType=ttDBase) )
 then begin
  filename := DBase.Directory + Tablename;
  if Empty(extension)then begin
   extension := '.DBF';
   filename := filename + '.DBF';
  end;
  if FileExists(Filename) then begin
        DBF := TFileStream.Create(Filename, fmOpenReadWrite + fmShareDenyNone);
  try
  DBF.Read(Header, SizeOf(Header));
  if Header.StructIDX then begin
  Filename := Copy(Filename, 1, Length(Filename) - Length(Extension));
  if TableLevel = 25
  then filename := filename + '.CDX'
  else filename := filename + '.MDX';
  if not FileExists(Filename) then begin
   Header.StructIDX := false;
   DBF.Seek (0, soFromBeginning);
   DBF.Write(Header, SizeOf(Header));
 end;
 end;              
finally
DBF.Free;
end;
end;
end;


0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question