Solved

Open a table without its index

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

10 Experts available now in Live!

Get 1:1 Help Now