Link to home
Start Free TrialLog in
Avatar of protein
protein

asked on

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

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.
Avatar of dwwang
dwwang

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.)
Hi,
in BDE Administrator you can specify, which level of table is created by default.

A.
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);
var
  pOptDesc, pOrigDesc: pFLDDesc;
  pOptData, pOrigData: pBYTE;
  TblDesc: CRTblDesc;
  sLevel, sBlockSize, sFillFactor: String;

begin
  pOptDesc := AllocMem(3 * sizeof(FLDDesc));
  pOrigDesc := pOptDesc;
  pOptData := AllocMem(20);
  pOrigData := pOptData;
  try
    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);
    Inc(pOptDesc);
    // 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);
    Inc(pOptDesc);
    // 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));
  finally
    FreeMem(pOrigDesc, 3 * sizeof(FLDDesc));
    FreeMem(pOrigData, 20);
  end;
end;
Avatar of protein

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of dwwang
dwwang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial