Solved

Open a table without its index

Posted on 1998-08-12
2
135 Views
Last Modified: 2010-04-04
How can I open a dBase Table when its associate index is not present ?
Well, if I try to open a table when its index associate is not present then BDE raise an exception. An solution for this problem should be open the table at design time but I can't do it because I don't know the table's name. I know the table's names just after run some code.
Somebody help me ?
0
Comment
Question by:ara72
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1361994
Hi ara72,

use DbiRegisterCallback,

an inprise example :

BDE API Examples (DbiRegisterCallback)
Registers a callback function for the client application.
--------------------------------------------------------------------------------
 
Example 1: Create a callback that handles the condition of a missing .MDX file for a dBASE file or a missing .CDX file for a FoxPro file:
//Function called by DbiRegisterCallBack
function myfunc(ecbType : CBType; iClientData : LongInt;
   pCbInfo : pCBInputDesc): CBRType; stdcall;
const
   READONLY = 'Read Only';
   FAILOPEN = 'Fail Open';  //The default
   OPENANDDETACH = 'Open and Detach';
var
  counter : integer;
begin
  case ecbtype of
    cbINPUTREQ:  //It's a callback of cbINPUTREQ type
      if pcbInfo.eCbInputId = cbiMDXMIssing then
      begin
        {
        //Simple loop to list all modes, could be used to give used
        //to give a choice
        for counter:= 0 to pcbInfo.iCount-1 do
          showmessage(pcbInfo.acbEntry[counter].szKeyWord + #13 +
                   pcbInfo.acbEntry[counter].szHelp);
        }
        for counter:=0 to pcbInfo.iCount-1 do
          if pcbInfo.acbEntry[counter].szKeyword = OPENANDDETACH then
          begin
            pcbInfo.iSelection:=counter+1;
            pcbInfo.bSave := FALSE;
            break;
          end;
      end
      else  //if
        ShowMessage('Unexpected eCbInputId');
  else  //Case
    ShowMessage('Unexpected ecbType')
  end;
end;

//Register the callback and open the table
procedure TForm1.Button2Click(Sender: TObject);
var
  cbinfo : CBInputDesc;
begin
  session.open;
  Check(DbiRegisterCallBack(
   nil,                          //Cursor (Optional)
   cbINPUTREQ,                   //Type of Callback
   longint(0),                   //Pass-through client data
   sizeof(CBInputDesc),          //Callback buffer len
   @cbinfo,                      //Pointer to callback function
   @myfunc                       //Call back fn being registered
));
   Table1.Open;

   //Unregister the callback
   Check(DbiRegisterCallBack(nil, cbINPUTREQ, 0, sizeof(CBInputDesc), nil , nil));
end;

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361995
ara72,

 an older solution :

Q:  I have a DBF table that I can't open because it is expecting an MDX (production index) file.  I lost (deleted) that file.  What do I do now?

A:  Byte 28 in the DBF file header indicates whether an MDX file is needed.  (0 = no MDX needed; 1 = MDX needed.)  Here is some code that makes the change for you.  It uses a radio group where the first item is NO MDX (element 0), and the second item is USES MDX (element 1).  This app also uses the TOpenDialog component.

procedure TForm1.Button1Click(Sender: TObject);
var
  f: file of byte;
  b: byte;
begin
  if OpenDialog1.execute then
  begin
    assignFile(f, OpenDialog1.FileName);
    reset(f);
    seek(f, 28);

    b := RadioGroup1.ItemIndex; {0 = no MDX; 1 = use MDX}
    write(f, b);
    closefile(f);
  end;
  OpenDialog1.FileName := '*.dbf'; {reset the filter}
end;

{ This code came from Lloyd's help file! }

Regards, zif.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 191
Delphi : could not find program, '...exe' 2 148
Intraweb download file link ? 1 110
How to debug For loops? 3 45
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

17 Experts available now in Live!

Get 1:1 Help Now