Solved

Open a table without its index

Posted on 1998-08-12
2
144 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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