Create dBase III/IV table with BDE API (5)

Posted on 1998-11-10
Last Modified: 2013-11-24
Hi experts.
I would like to create a dBase III/IV table with the help of BDE API functions. dbiCreateTable function creates a dBase file, but it is a dBASE 5 table (because my BDE is version 5). Is there any parametar that i can pass to this function so that it creates a dBase II/IV table?
Thx in advance.
Question by:protein
  • 3

Expert Comment

ID: 1346370
Have looked at the example in BDE32.hlp for the dbiCreateTable function? I think the level parameter of a table is the version. So you can have a try to set it to different values to check out whether the expected version is created. (Although I think set level to 4 is proper.)

Expert Comment

ID: 1346371
in BDE Administrator you can specify, which level of table is created by default.


Expert Comment

ID: 1346372
Yes, either way will do the trick. If you want to be able to create different versions of DBase tables, the parameter in the dbicreate table is needed. Below is the example in BDE32.hlp:

Create a table with a different level, block size, and fill factor than specified in the BDE configuration. Most Delphi users should use TTable.CreateTable. This example uses the following input:
      fDbiCreateTable(Database1.Handle, 'TableChange', 3, @FDesc, 7, 32768, 95);

procedure fDbiCreateTable(hTmpDb: hDBIDb; TableName: String; Fields: Word;
             pFlds: pFLDDesc; Level, BlockSize, FillFactor: Word);
  pOptDesc, pOrigDesc: pFLDDesc;
  pOptData, pOrigData: pBYTE;
  TblDesc: CRTblDesc;
  sLevel, sBlockSize, sFillFactor: String;

  pOptDesc := AllocMem(3 * sizeof(FLDDesc));
  pOrigDesc := pOptDesc;
  pOptData := AllocMem(20);
  pOrigData := pOptData;
    sLevel := IntToStr(Level);
    sBlockSize := IntToStr(BlockSize);

    sFillFactor := IntToStr(FIllFactor);
    // Set up first parameter
    pOptDesc.iOffset := 0;
    pOptDesc.iLen := Length(sLevel) + 1;
    StrPCopy(pOptDesc.szName, 'LEVEL');
    StrPCopy(PChar(pOptData), sLevel);
    Inc(pOptData, Length(sLevel) + 1);
    // Set up second parameter
    pOptDesc.iOffset := Length(sLevel) + 1;
    pOptDesc.iLen := Length(sLevel) + 1 + Length(sBlockSize) + 1;
    StrPCopy(pOptDesc.szName, 'BLOCK SIZE');
    StrPCopy(PChar(pOptData), sBLockSize);

    Inc(pOptData, Length(sBlockSize) + 1);
    // Set up third parameter
    pOptDesc.iOffset := Length(sLevel) + 1 + Length(sBlockSize) + 1;
    pOptDesc.iLen := Length(sLevel) + 1 + Length(sBlockSize) + 1 + Length(sFillFactor) + 1;
    StrPCopy(pOptDesc.szName, 'FILL FACTOR');
    StrPCopy(PChar(pOptData), sFillFactor);
    // Format the table descriptor
    FillChar(TblDesc, sizeof(TblDesc), #0);
    StrPCopy(TblDesc.szTblName, TableName);
    StrCopy(TblDesc.szTblType, szPARADOX);

    TblDesc.iOptParams := 3;
    TblDesc.pFldOptParams := pOrigDesc;
    TblDesc.pOptData := pOrigData;
    TblDesc.iFldCount := Fields;
    TblDesc.pFldDesc := pFlds;
    // Create the table
    Check(DbiCreateTable(hTmpDb, True, TblDesc));
    FreeMem(pOrigDesc, 3 * sizeof(FLDDesc));
    FreeMem(pOrigData, 20);

Author Comment

ID: 1346373
Thank u for answering, but there is still a problem:
I have already read the code above, but the LEVEL parametar is described in the BDE help in this way: If you want to create a FOxPro 2.5 table you must create dBase table with an optional LEVEL parametar 25. That is OK for FoxPro, but i want to create a dBase III/IV table.
For example if i pass as Level- 7 that meens Paradox7 table, but what about Level=5??? Is this going to be a Paradox5 or dBase5 table.
About the other comment from A.: I want to make this programmatically(the average user does not know how to use the BDE administrator

Accepted Solution

dwwang earned 210 total points
ID: 1346374
The parameter of the function also includes a tableType item, in it you can define the table type programmatically, like the statement above:

StrCopy(TblDesc.szTblType, szPARADOX);

you can write StrCopy(TblDesc.szTblType, szDBASE) to create a DBase table.

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

947 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

21 Experts available now in Live!

Get 1:1 Help Now