Solved

IndexFile missing Dbase

Posted on 1998-05-19
1
412 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now