Yes, I think I have what you are looking for.
You have to 'work on it'. Change files-type etc...
This is for BDE. For BDE-alternatives (like ADO,TinyTable,etc, the whole
differs of course)

Between the lines is the article.

...go for it

Omer

=====================================================================

How to Create a Table at Runtime

----------------------------------------------------------------------------
----

I was a VB programmer, until my recent shift to Delphi 2.0. How can I create
a database in code?


----------------------------------------------------------------------------
----

It depends on the type of database you want to build. However, I can show
you how to do it with a Paradox table. Conceivably, it stands to reason that
since the TTable is database-independent and if you've got the right
settings in the BDE, you should be able to create a table with the TTable
component in any database. This is not necessarily true. SQL tables are
normally created using the SQL call CREATE TABLE. And each server has its
own conventions for creating tables and defining fields. So it's important
to note this if you're working with a SQL database. The problem is that SQL
databases support different data types that aren't necessarily available in
the standard BDE set. For instance, MS SQL server's NUMERIC data format is
not necessarily a FLOAT as it's defined in the BDE. So your best bet would
probably be to create SQL tables using SQL calls.

What you have to do is declare a TTable variable, create an instance, then
with the TTable's FieldDefs property, add field definitions. Finally, you'll
make a call to CreateTable, and your table will be created. Here's some
example code:

{ "Add" is the operative function here.
  Add(const Name: string; DataType: TFieldType; Size: Word; Required:
Boolean);
}
procedure CreateATable(DBName,            //Alias or path
                       TblName : String); //Table Name to Create
var
  tbl : TTable;
begin
  tbl := TTable.Create(Application);
  with tbl do begin
    Active := False;
    DatabaseName := DBName;
    TableName := TblName;
    TableType := ttParadox;
    with FieldDefs do begin
      Clear;
      Add('LastName', ftString, 30, False);
      Add('FirstName', ftString, 30, False);
      Add('Address1', ftString, 40, False);
      Add('Address2', ftString, 40, False);
      Add('City', ftString, 30, False);
      Add('ST', ftString, 2, False);
      Add('Zip', ftString, 10, False);
    end;

    {Add a Primary Key to the table}
    with IndexDefs do begin
      Clear;
      Add('Field1Index', 'LastName;FirstName', [ixPrimary, ixUnique]);
    end;

    CreateTable; {Make the table}
  end;
end;
The procedure above makes a simple contact table, first by defining the
fields to be included in the table, then creating a primary key. As you can
see, it's a pretty straightforward procedure. One thing you can do is to
change the TableType property setting to a variable that's passed as a
parameter to the procedure so you can create DBase or even ASCII tables.
Here's snippet of how you'd accomplish that:

procedure CreateATable(DBName,                //Alias or path
                       TblName : String);     //Table Name to Create
                       TblType : TTableType); //ttDefault, ttParadox,
ttDBase, ttASCII
var
  tbl : TTable;
begin
  tbl := TTable.Create(Application);
  with tbl do begin
    Active := False;
    DatabaseName := DBName;
    TableName := TblName;
    TableType := TblType;
    with FieldDefs do begin
      Clear;
      Add('LastName', ftString, 30, False);
      Add('FirstName', ftString, 30, False);
      Add('Address1', ftString, 40, False);
      Add('Address2', ftString, 40, False);
      Add('City', ftString, 30, False);
      Add('ST', ftString, 2, False);
      Add('Zip', ftString, 10, False);
    end;

    {Add a Primary Key to the table}
    with IndexDefs do begin
      Clear;
      Add('Field1Index', 'LastName;FirstName', [ixPrimary, ixUnique]);
    end;

    CreateTable; {Make the table}
  end;
end;
Pretty simple, right? One thing you should note is that the TableType
property is only used for desktop databases. It doesn't apply to SQL tables.

Oh well, that's it in a nutshell. Have fun!

============================================================================
=======

----- Original Message -----
From: "Ercan Erdošan" <[EMAIL PROTECTED]>
To: <delphi-en@yahoogroups.com>
Sent: Tuesday, April 26, 2005 2:26 PM
Subject: Re: [delphi-en] dynamically adding field to paradox table at
runtime



i cant tell my problem, i want to add new field to table
this field type is "blob", i dont want to add field value,


Omer Yasar Can <[EMAIL PROTECTED]> wrote:
How about this (by Peter Below):

Procedure GetArrayData( Var WR: WorkRec );
Var
  bs: TBlobstream;
Begin
  Assert( assigned( WR.WRBlobFld ));

  bs:= TBlobstream.Create( WR.WRBlobFld, bmRead );
  try
    bs.Read( WR.WRArrayFld, sizeof(WR.WRArrayFld ));
  finally
    bs.free;
  end;
End;

To put the data back into the field you put the dataset in Edit
mode and call

Procedure PutArrayData( Const WR: WorkRec );
Var
  bs: TBlobstream;
Begin
  Assert( assigned( WR.WRBlobFld ));

  bs:= TBlobstream.Create( WR.WRBlobFld, bmWrite );
  try
    bs.Write( WR.WRArrayFld, sizeof(WR.WRArrayFld ));
  finally
    bs.free;
  end;
End;

Good luck

Omer
  ----- Original Message -----
  From: Ercan Erdošan
  To: delphi-en@yahoogroups.com
  Sent: Tuesday, April 26, 2005 11:14 AM
  Subject: [delphi-en] dynamically adding field to paradox table at runtime


  hi all,
  i want to add blob field to paradox table, (not field value)
  how can i this?

  thanx for help now


  ---------------------------------
  Do you Yahoo!?
  Yahoo! Small Business - Try our new resources site!

  [Non-text portions of this message have been removed]



  -----------------------------------------------------
  Home page: http://groups.yahoo.com/group/delphi-en/
  To unsubscribe: [EMAIL PROTECTED]



----------------------------------------------------------------------------
--
  Yahoo! Groups Links

    a.. To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

    b.. To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



[Non-text portions of this message have been removed]



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]



---------------------------------
Yahoo! Groups Links

   To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/

   To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



Ercan Erdošan

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

[Non-text portions of this message have been removed]



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links










-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to