[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

IndexFile missing Dbase

Posted on 1998-05-19
1
Medium Priority
?
458 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 280 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…

830 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