Board index » delphi » Creating a database at runtime

Creating a database at runtime

How does one create a database at runtime (that will use the BDE in DP
4.0x)?

(I can't help but think I'm asking the "wrong" question because I can't
find any reference to this in the docs, but it's essentially what I want
to do. Thus far I have only created databases using Database Desktop,
but that won't do in my final application).

-Ted

 

Re:Creating a database at runtime


Hi

    Look this procedure:

procedure WForm1.CreateSales;
begin

  with TableSales do
    begin

      DatabaseName := '<your database name>';
      TableType := DBTables.ttParadox;
      TableName := 'Sales';

      with FieldDefs do
        begin
          Clear;
          Add('Number', ftAutoInc, 0, False);
          Add('Customer',   ftString, 40, False);
          Add('Value',  ftFloat, 0, False);
        end;

      with IndexDefs do
        begin
          Clear;
          {Primary Key}
          Add('', 'Number', [ixPrimary, ixUnique]);
        end;

      CreateTable;
    end;

end;

Cristiano Carneiro
Ctba - Brazil

Ted Michon escreveu na mensagem <378A1CEE.51392...@home.com>...

Quote
>How does one create a database at runtime (that will use the BDE in DP
>4.0x)?

>(I can't help but think I'm asking the "wrong" question because I can't
>find any reference to this in the docs, but it's essentially what I want
>to do. Thus far I have only created databases using Database Desktop,
>but that won't do in my final application).

>-Ted

Re:Creating a database at runtime


Cristiano-

Thanks for the very quick reply. I added CreateSales := tTable.Create(self)
and plugged in a database name (I keep forgetting that database names are
directories, not files <g>) and it seemed to work just fine (at least there
were no run time errors and when I looked there were <my database name>.db
and <my database name>.px files in the target directory).

Thanks very much.

-Ted

Quote
Cristiano Carneiro wrote:
> Hi

>     Look this procedure:

> procedure WForm1.CreateSales;
> begin

>   with TableSales do
>     begin

>       DatabaseName := '<your database name>';
>       TableType := DBTables.ttParadox;
>       TableName := 'Sales';

>       with FieldDefs do
>         begin
>           Clear;
>           Add('Number', ftAutoInc, 0, False);
>           Add('Customer',   ftString, 40, False);
>           Add('Value',  ftFloat, 0, False);
>         end;

>       with IndexDefs do
>         begin
>           Clear;
>           {Primary Key}
>           Add('', 'Number', [ixPrimary, ixUnique]);
>         end;

>       CreateTable;
>     end;

> end;

> Cristiano Carneiro
> Ctba - Brazil

> Ted Michon escreveu na mensagem <378A1CEE.51392...@home.com>...
> >How does one create a database at runtime (that will use the BDE in DP
> >4.0x)?

> >(I can't help but think I'm asking the "wrong" question because I can't
> >find any reference to this in the docs, but it's essentially what I want
> >to do. Thus far I have only created databases using Database Desktop,
> >but that won't do in my final application).

> >-Ted

Re:Creating a database at runtime


Are you trying to create a database or a table in a database?  What database
are you using (Paradox, Access, Dbase,...)?

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Re:Creating a database at runtime


Bill-

1. In this situation, I'm trying to create both a database and a table in it.

2. I'm not using a separate database, just the BDE supplied with DP4 and
selecting ttDefault.

(Perhaps I'm missing a main idea here somewhere -- it certainly feels that way
at times <g>).

-Ted

Quote
Bill Todd wrote:
> Are you trying to create a database or a table in a database?  What database
> are you using (Paradox, Access, Dbase,...)?

> Bill

> --

> Bill Todd - TeamB
> (TeamB cannot respond to email questions. To contact me
>  for any other reason remove nospam from my address.)

Re:Creating a database at runtime


The BDE allows you to work with many different database management systems
(Paradox, dBase, Access, Oracle, Informix, SQL Server, Interbase and
others). If you are just starting a good database to begin with is Paradox
tables since you do not need anything but the BDE (the same is true for
dBase tables).

A database is a collection of tables. For Paradox and dBase tables a
database is simply a subdirectory in which you will place your tables. The
easiest way to create a table is to use the Database Desktop. If you want to
create a table in code use the CreateTable method of the TTable component as
follows.

with Table1 do
begin
  DatabaseName := 'MyAlias';
  TableName := 'foo.db';
  with FieldDefs do
  begin
    Add('First Field', ftInteger, 0, False);
    Add('Second Field', ftString, 32, False);
  end;
  CreateTable;
end;

If this is not what you need ask more questions<g>.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Other Threads