|
<< Click to Display Table of Contents >> Delphi Examples: DbiRenameTable |
![]() ![]()
|
Rename the table to the new table name. If ReOpen is True, reset the table's TableName and reopen the table.
| Note: | Most Delphi users should use TTable.RenameTable method. |
procedure fDbiRenameTable(Table: TTable; NewName: String; ReOpen: Boolean);
var
hDb: hDBIDb;
Props: CURProps;
begin
if not Table.Active then
EDatabaseError.Create('Table must be open to complete operation');
if not Table.Exclusive then
EDBEngineError.Create(DBIERR_NEEDEXCLACCESS);
Check(DbiGetCursorProps(Table.Handle, Props));
// Get the Database Handle from the table cursor since Table.DBHandle will
// be invalid once the table is closed
Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
Table.Close;
Check(DbiRenameTable(hDb, PChar(Table.TableName), Props.szTableType, PChar(NewName)));
if ReOpen then begin
Table.TableName := NewName;
Table.Open;
end;
end;