Solved

add field at run time

Posted on 2000-03-11
15
159 Views
Last Modified: 2010-05-18
Is is possible to add a field to a table at run time? If it is possible, can you give me a sample code? Thanks!
0
Comment
Question by:xiangenhu
  • 4
  • 4
  • 3
  • +3
15 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2607893
You can use SQL to do that in most cases:

procedure TDataForm.CreateTableButtonClick(Sender: TObject);

var
  SQLstmt: String;
begin
  Database1.Connected := True;
  SQLstmt := 'CREATE TABLE NewCusts ' +
    '( ' +
    '  CustNo INTEGER, ' +
    '  Company CHAR(40), ' +
    '  State CHAR(2), ' +
    '  PRIMARY KEY (CustNo) ' +
    ')';
  Database1.Execute(SQLstmt, nil, False, nil);
end;
0
 
LVL 15

Expert Comment

by:simonet
ID: 2608039
FOllowing...
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 2608047
hi eps,

thats not exactly what is asked for

hi xiangenhu,
you can use a sql statement like this

alter table YourTableName add testCol char(10)

just put it in a query and use the execSQL-method

sample (Databasename is properly filled):
query1.Clear;
query1.Sql.Add('alter table YourTableName add testCol char(10)');
try
  query1.ExecSQL;
except
  //there was an error
end;

meikl

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2608053
hi alex ;-)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2608087
Epsylon changed the proposed answer to a comment
0
 
LVL 15

Expert Comment

by:simonet
ID: 2608097
Hello, Meikl! Hello, Epsylon! How are you folks?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2608154
Everything's going ok here, thanks. How are you?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:simonet
ID: 2608370
Quite fine, thanks! Just bought Delphi 5 Developers Guide, and there's really a lot to read... lots of thing I gotta catch up with.

Alex
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2609184
hi both,

i'm fine too. have terrible much work at last time.
working on three projects at same time.
Delphi 5 Developers Guide seems to be good.
shall i buy it, too?

well, nice to meet you.

meikl
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2610908
listen
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2611145
Hi,

This has absulutely nothing to do with the question, but Meikl or Alex, is the Delphi 5 Developers Guide worth buying ?

I have bought the Delphi 5 Enterprise a few months ago, and am really looking for some good books.

Thanks a lot,

Stefaan
0
 

Author Comment

by:xiangenhu
ID: 2612708
Great answer. I have implemented and it works! Thanks a lot!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2613120
hi xiangenhu,

glad to helped you
good luck again.

to stefaan,
i don't have it and i want also to know if this a good book.
btw. how are you?

to alex,
can you tell a bit about the book?

meikl
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2613687
Meikl,

Well, I'm back from wherever I was ;-)
Had quite a lot of work to do, but now that it is done, I'm back to some Experts-Exhange work again.

By the way, I just ordered the book, so I hope it will be a good one ;-)

Best regards,


Stefaan
0
 
LVL 15

Expert Comment

by:simonet
ID: 2614505
Sure... the book is very good, pretty much worth the money.

I also have Delphi 2 Developer's Guide, and there are many things in common, many similar chapters. But D5 DDG inovates in what Delphi 5: COM, CORBA, MTS-support, Internet development, etc.

Besides, there's a direct channel to the authors, Steve Texeira and Xavier Pacheco, through their own newsgroup.

The only think I believe the book lacks is not covering enough of the OpenTools API. Since many things changed from D4 to D5 regarding the OpenTools API, I believe D5 DDG should cover some of it. After all, Ray Lischner's book, Hidden Paths of Delphi 3, is already getting outta date.

Anyhow, it's a must-have for any serious Delphi developer. I rate it 4 1/2 stars (out of 5 max)

Alex
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now