Board index » delphi » Problems creating a .dbf table in runtime

Problems creating a .dbf table in runtime

Ive had some problems creating a .dbf table in runtime.
I need to create a new table, that belongs to  no existing database.

I made some changes to the code from  the createtable example in the Delphi
5 help. It seems to work fine, the table is created and can be used by data
aware controls in other deplhi created applications, but neither Acces 97
nor Excel 97 recognize de table as a dbase .dbf file.

I dont know what Im doing wrong, can anybody help me?? I

The Borland Database Desktop has no problems reading my created .dbf file
and recognizes it as a Windows dBase File.

I dont know the way to create and save my table in runtime for de dBase III
or dbaseIV.

These .dbf formats are listed as supported by the MS Excel, but not Dbase
for Windows.

Is there any way for telling the BDE to save de .dbf as a dBASE III File?

Thank you.

                                                                        Luis
Avila

Here is the code I use to create the tables, it is taked from the examples
given by de Delphi Help.
It is formerly supposed to create a paradox table, and slightly modified to
do the same job with a dbase file.

procedure TForm1.Button1Click(Sender: TObject);
var

  TableFound: Boolean;
begin
  NewTable := TTable.Create(Self);
  NewTable.TableLevel:=strtoint(Edit4.Text);
  NewTable.TableLevel:=strtoint(Edit4.Text);
  with NewTable do
    begin
      Active := False;
      DatabaseName := 'd:\Files';
      TableName := Edit1.Text;
      TableType := ttdBASE;
      FieldDefs.Clear;
      FieldDefs.Add(Edit2.Text, ftfloat, 0, False);
      FieldDefs.Add(Edit3.Text, ftfloat, 0, False);
      CreateTable;
      DataSource1.DataSet:=NewTable;
      Active:=true;
  end;

end;

 

Re:Problems creating a .dbf table in runtime


skoter...@NOSPAMborland.com escribi en mensaje
<38db3e90.24899...@forums.borland.com>...

Quote
>On Wed, 22 Mar 2000 13:37:58 -0500, "Luis Avila"
><heno...@amauta.rcp.net.pe> wrote:

>>Ive had some problems creating a .dbf table in runtime.
>>I need to create a new table, that belongs to  no existing database.

>For local table types (dBASE and Paradox), a "database" is a directory
>on the host computer. So unless you put the file in the root directory
>of a drive, it will always below to a database (directory).

>>I made some changes to the code from  the createtable example in the
Delphi
>>5 help. It seems to work fine, the table is created and can be used by
data
>>aware controls in other deplhi created applications, but neither Acces 97
>>nor Excel 97 recognize de table as a dbase .dbf file.

>This is probably due to a shortcoming in Microsoft Access and/or
>Excel. I suspect your dBASE table is a level 7 table, which is beyond
>the capabilities of those software packages to use. Inspect the table
>in the Database Explorer utility (or SQL Explorer, whichever you have)
>to verify its level.

>>I dont know what Im doing wrong, can anybody help me?? I

>>The Borland Database Desktop has no problems reading my created .dbf file
>>and recognizes it as a Windows dBase File.

>>I dont know the way to create and save my table in runtime for de dBase
III
>>or dbaseIV.

>>These .dbf formats are listed as supported by the MS Excel, but not Dbase
>>for Windows.

>>Is there any way for telling the BDE to save de .dbf as a dBASE III File?

>What version of Delphi are you using?

>(Follow-ups to the newsgroup only, please.)

>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\
>Steve Koterski                    "If you aren't fired with
>Technical Publications            enthusiasm, you will be
>Borland                           fired with enthusiasm."
>                              -- Vince Lombardi (1913-1970)

Im using
Delphi 5.0 Build 5.62 Professional

Re:Problems creating a .dbf table in runtime


On Wed, 22 Mar 2000 13:37:58 -0500, "Luis Avila"

Quote
<heno...@amauta.rcp.net.pe> wrote:
>Ive had some problems creating a .dbf table in runtime.
>I need to create a new table, that belongs to  no existing database.

For local table types (dBASE and Paradox), a "database" is a directory
on the host computer. So unless you put the file in the root directory
of a drive, it will always below to a database (directory).

Quote
>I made some changes to the code from  the createtable example in the Delphi
>5 help. It seems to work fine, the table is created and can be used by data
>aware controls in other deplhi created applications, but neither Acces 97
>nor Excel 97 recognize de table as a dbase .dbf file.

This is probably due to a shortcoming in Microsoft Access and/or
Excel. I suspect your dBASE table is a level 7 table, which is beyond
the capabilities of those software packages to use. Inspect the table
in the Database Explorer utility (or SQL Explorer, whichever you have)
to verify its level.

Quote
>I dont know what Im doing wrong, can anybody help me?? I

>The Borland Database Desktop has no problems reading my created .dbf file
>and recognizes it as a Windows dBase File.

>I dont know the way to create and save my table in runtime for de dBase III
>or dbaseIV.

>These .dbf formats are listed as supported by the MS Excel, but not Dbase
>for Windows.

>Is there any way for telling the BDE to save de .dbf as a dBASE III File?

What version of Delphi are you using?

(Follow-ups to the newsgroup only, please.)

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\
Steve Koterski                    "If you aren't fired with
Technical Publications            enthusiasm, you will be
Borland                           fired with enthusiasm."
                              -- Vince Lombardi (1913-1970)

Re:Problems creating a .dbf table in runtime


On Wed, 22 Mar 2000 13:37:58 -0500, "Luis Avila"

Quote
<heno...@amauta.rcp.net.pe> wrote:
>Is there any way for telling the BDE to save de .dbf as a dBASE III File?
[snip]
>      FieldDefs.Add(Edit2.Text, ftfloat, 0, False);
>      FieldDefs.Add(Edit3.Text, ftfloat, 0, False);

Change this to:
     FieldDefs.Add(Edit2.Text, ftBCD, 4, False);
     FieldDefs.Items[FieldDefs.Count - 1].Precision := 19;
     FieldDefs.Add(Edit3.Text, ftBCD, 4, False);
     FieldDefs.Items[FieldDefs.Count - 1].Precision := 19;

A few things to watch to create dBaseIII/IV tables:
- use ftBCD as field type for numeric and mind the peculiar
significance of the Precision and Size field for that field type;
- don't use required fields;
- don't use any other field types not supported by dBase III/IV.

HTH,

Jan

Re:Problems creating a .dbf table in runtime


On Wed, 22 Mar 2000 23:28:12 -0500, "Luis Avila"

Quote
<heno...@amauta.rcp.net.pe> wrote:

[...]

Quote
>Im using
>Delphi 5.0 Build 5.62 Professional

Try using the TTable.TableLevel property to control the output table's
level. Note that this only applies when creating a table through that
TTable.

Also check out the BDE configuration setting LEVEL for the native
dBASE driver. Use the BDE Administrator to check this value or to
change it.

And when creating tables, do not use features that are only supported
in higher table levels than what you wish to create. For example,
features like AUTOINC and INTEGER column types are only supported for
level 7. You cannot create a level 3, 4, or 5 dBASE tables *and* use
one of these features.

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\
Steve Koterski                    "If you aren't fired with
Technical Publications            enthusiasm, you will be
Borland                           fired with enthusiasm."
                              -- Vince Lombardi (1913-1970)

Re:Problems creating a .dbf table in runtime


On Thu, 23 Mar 2000 08:39:44 GMT, j...@nospamplease.adm2000.be (Jan

Quote
Sprengers) wrote:

[...]

Quote
>Change this to:
>     FieldDefs.Add(Edit2.Text, ftBCD, 4, False);
>     FieldDefs.Items[FieldDefs.Count - 1].Precision := 19;
>     FieldDefs.Add(Edit3.Text, ftBCD, 4, False);
>     FieldDefs.Items[FieldDefs.Count - 1].Precision := 19;

[...]

Another way to do the same thing is using the TFieldDefs.AddFieldDef
method. Call the method and then set all of the new TFieldDef object's
properties.

  with FieldDefs.AddFieldDef do begin
    Name := Edit2.Text;
    DataType := ftBCD;
    Size := 4;
    Precision := 19;
    Required := False;
  end;

Note that these two approaches -- Jan Sprenger's and mine -- do
exactly the same thing. They are merely two ways to get the same
result.

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\
Steve Koterski                    "If you aren't fired with
Technical Publications            enthusiasm, you will be
Borland                           fired with enthusiasm."
                              -- Vince Lombardi (1913-1970)

Re:Problems creating a .dbf table in runtime


skoter...@NOSPAMborland.com escribi en mensaje
<38e139fe.2500...@forums.borland.com>...

Quote
>On Wed, 22 Mar 2000 23:28:12 -0500, "Luis Avila"
><heno...@amauta.rcp.net.pe> wrote:

>[...]

>>Im using
>>Delphi 5.0 Build 5.62 Professional

>Try using the TTable.TableLevel property to control the output table's
>level. Note that this only applies when creating a table through that
>TTable.

>Also check out the BDE configuration setting LEVEL for the native
>dBASE driver. Use the BDE Administrator to check this value or to
>change it.

>And when creating tables, do not use features that are only supported
>in higher table levels than what you wish to create. For example,
>features like AUTOINC and INTEGER column types are only supported for
>level 7. You cannot create a level 3, 4, or 5 dBASE tables *and* use
>one of these features.

Thank you, changing the driver level in the BDE Administrator fixed the
problem, but i would like to find another solution.

I dont like every user changing the driver level in the BDE ADminisrtator
in order to have the program working.

Re:Problems creating a .dbf table in runtime


On Thu, 23 Mar 2000 22:03:07 -0500, "Luis Avila"

Quote
<heno...@amauta.rcp.net.pe> wrote:

[...]

Quote
>Thank you, changing the driver level in the BDE Administrator fixed the
>problem, but i would like to find another solution.

>I dont like every user changing the driver level in the BDE ADminisrtator
>in order to have the program working.

Well, you can much about in the Windows Registry. However, a change to
the LEVEL parameter does not affect a currently running BDE session.
You would need to quit and reinitialize the BDE for it to have an
effect. OTOH, that *is* typical of an application installation
situation...

Below is the Registry node hierarchy leading to this parameter (on my
computer, which is running NT).

  HKEY_LOCAL_MACHINE
    SOFTWARE
      Borland
        Database Engine
          Settings
            DRIVERS
              DBASE
                TABLE CREATE

In that last section you will find the LEVEL parameter. Read up on
using the TRegistry component for making this change or InstallShield
Express (can it do this?).

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\
Steve Koterski                    "If you aren't fired with
Technical Publications            enthusiasm, you will be
Borland                           fired with enthusiasm."
                              -- Vince Lombardi (1913-1970)

Other Threads