Solved

IndexFile missing Dbase

Posted on 1998-05-19
1
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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 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…

737 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