Adding Table-field?

Is it possible to add a field to a table ?
I tried to add field 'test'  like this:
With Table1.FieldDefs do

This works, but the information already in the table disappears (of course). Can I add a field without emptying the table?

Ps. I use Delphi Developer 2.0 and the table is a DBase IV.

Thank you
Erik N
Erik NAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It's normal that you get an empty table. CreateTable is your problem. I'll look for a solution:

The CreateTable method creates a new empty database table. Before calling this method, the DatabaseName, TableName, TableType, FieldDefs and IndexDefs properties must be assigned values.
The easiest way to do this would be to use an SQL statement.  Here is a code snippet for you: (must use DB, DBTables)============================
  with TQuery.Create(Application) do
      SQL.Add('ALTER TABLE "<your tables path full path.dbf>"
              ADD <your field name> <data type');
See CREATE TABLE in your Borland\Common Files\BDE\LocalSQL.hlp for the allowed data_type's.

An example for the add statement would be:
  SQL.Add('ALTER TABLE "C:\test.dbf" ADD NAME CHAR(15)');

You could probably also do it with a DBI call... but it would be much more difficult.
Erik NAuthor Commented:
Sorry Doldrum, SQL-statements is like chinese for me. I would like to do this without using SQL, if possible....

To ZifNab: I appreciate it !!

Thanx !!
Erik N.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Sorry, at the moment I can't find an easy solution. But may I ask why you need a field to a table? Why don't you just use a calculated field?
At the moment : If you don't want to use SQL, you can create a totally new table with your new field and then use the TBatchmove component in mode batUpdate. To copy the records for your first table to your new table.
But still, I'd like to have an answer to my quistion, if it's possible.
You need to use the batchmove component.

Follow these steps

1 create a temporary table with the new field
2 Use Batchmove to copy the existing records into the temp table
3 delete original table
4 rename temporary table to original table.

This could be dangerous in a multi-user environment.
If you need multiuser support use the SQL

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I don't know if you know it, but your answer looks very much like my comment. I hope you didn't saw this, because otherwise I get strange feelings about it.

No I didn't see your comment last time. If you ment is as an answer you should have indicated this and the system would have locked me out.
essbb, didn't gave it as an answer because it's not really a beautifull answer. But if he likes it, he could use it.
Have fun,
Erik N!
Sorry, I made a mistake! It's possible, I'll give you the function: DbiDoRestructure.
Want more information, just ask!
c.u. ZifNab;

Erik NAuthor Commented:
Thank you essbb for your answer!

I would also like to thank ZifNab for his comments..
(I want the user to be able to add a field to the table in order to adapt the application to new situations. So the application won't be crap the minute the situation changes.)

I guess the only right thing to do here is to use SQL after all...

Erik N
Erik NAuthor Commented:
I really would like the info about DbiDoStructure (if possible)!!
Hope you see this..

Erik N
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.