Solved

add field at run time

Posted on 2000-03-11
15
162 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 99
FMX enumerated colours 2 101
URL for downloading Google Chrome for Win XP 2 159
How to renew a Delphi rad-studio licence? 5 65
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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