Solved

add field at run time

Posted on 2000-03-11
15
158 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

17 Experts available now in Live!

Get 1:1 Help Now