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

Comment Utility
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

Comment Utility
in BDE Administrator you can specify, which level of table is created by default.


Expert Comment

Comment Utility
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

Comment Utility
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
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

762 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

12 Experts available now in Live!

Get 1:1 Help Now