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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

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…
The canonical version of this article is on my web site here: A companion presentation is available here:
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

726 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