Hi John.
IndexDefs is actually an array of all the indexes of your table, so
since you want all the indexes anyway you can remove the commented out
lines from your code:
with tblSource do
begin
databaseName := sDBaseName;
tableName := sSourceTableName;
// IndexName := sIndexName; Not required
end;
with tblDest do
begin
databaseName := sDbaseName;
tableName := sDestTableName;
// IndexName := sIndexName; Not required
end;
And remove sIndexName from the function definition. I don't know
whether that was confusing CreateTable, but I made this change and
tested it and your procedure worked fine for me - created a table and
all the indexes for it, with or without data. Hope it works for you
too!
Cheers,
Carl Reynolds Ph: +64-9-4154790
CJN Technologies Ltd. Fax: +64-9-4154791
[EMAIL PROTECTED] DDI: +64-9-4154795
PO Box 302-278, North Harbour, Auckland, New Zealand
12 Piermark Drive, North Harbour Estate, Auckland, NZ
Visit our website at http://www.cjntech.co.nz/
> -----Original Message-----
> From: John Christenhusz [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, April 01, 1999 10:15 AM
> To: Multiple recipients of list delphi
> Subject: Cloning a table
>
> Hi all,
>
> I'm trying to create a clone table at run-time and use the following
> code. It creates the clone table all right, but it doesn't create the
> index with it.
>
> Any ideas?
>
> Ps. This routine creates only the assigned index (supposing it works).
> Is there a way to create ALL indexes without having to specify which
> you want?
>
> Thanks for your help.
>
> function CreateCloneTable(sDbaseName, sSourceTableName,
> sDestTableName, sIndexName : string; vtTableContent : tTableContent) :
> boolean;
> {Function:
> Create a copy of the source table in the destination table
> (including any indexes etc.
> Entry Parameters:
> sDbaseName = name of dbase
> sSourceTableName = source table name
> sDestTableName = destination table name
> sIndexName = name of secondary index to create
> vtTableContent = defines empty table or copy data
> Returns:
> True if completed successfully.}
> var
> tblSource : TTable;
> tblDest : TTable;
> bmBatchMove : TBatchMove;
> begin
> result := true;
> try
> tblSource := TTable.create(nil);
> tblDest := TTable.create(nil);
>
> with tblSource do
> begin
> databaseName := sDBaseName;
> tableName := sSourceTableName;
> IndexName := sIndexName;
> end;
>
> with tblDest do
> begin
> databaseName := sDbaseName;
> tableName := sDestTableName;
> IndexName := sIndexName;
> end;
>
> with tblDest do
> try
> close;
> tblSource.fieldDefs.update;
> fieldDefs.assign(tblSource.fieldDefs);
> tblSource.IndexDefs.update;
> indexDefs.assign(tblSource.indexDefs);
> createTable; // create the clone table
>
> // copy data to the new table if required
> if vtTableContent = tCopyData then
> begin
> bmBatchMove := TBatchMove.create(nil);
> with bmBatchmove do
> begin
> source := tblSource;
> destination := tblDest;
> mode := batAppend;
> execute;
> end;
> bmBatchMove.free;
> end;
> except
> result := false;
> end;
> tblSource.free;
> tblDest.free;
> except
> result := false;
> end;
> end;{CreateCloneTable}
>
> John Christenhusz
> POSTEC DATA SYSTEMS Ltd.
> PO Box 302-230
> Auckland, New Zealand
> E-mail: [EMAIL PROTECTED]
> Phone: 09-415.8803
> Fax: 09-415.9042
>
>
application/ms-tnef