Menu

#1 Restructuring Example

open
nobody
None
5
2001-08-25
2001-08-25
Anonymous
No

procedure RestructureTable(Table: TTable; Option, OptData: string);
var
hDb: hDBIDb;
TblDesc: CRTblDesc;
Props: CurProps;
pFDesc: FLDDesc;

begin
table.Exclusive:=false;
table.active:=false;
table.Exclusive:=true;
table.active:=true;
// If the table is not opened, raise an error. Need the table open to get
// the table directory.
if Table.Active <> True then
raise EDatabaseError.Create('Table is not opened');
// If the table is not opened exclusively, raise an error. DbiDoRestructure
// will need exclusive access to the table.
if Table.Exclusive <> True then
raise EDatabaseError.Create('Table must be opened exclusively');
// Get the table properties.
Check(DbiGetCursorProps(Table.Handle, Props));
// If the table is not a Paradox type, raise an error. These options only
// work with Paradox tables.
if StrComp(Props.szTableType, szPARADOX) <> 0 then
raise EDatabaseError.Create('Table must be of type PARADOX');
// Get the database handle.

Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
// Close the table.
Table.Close;
// Setup the Table descriptor for DbiDoRestructure
FillChar(TblDesc, SizeOf(TblDesc), #0);
StrPCopy(TblDesc.szTblName, Table.Tablename);
StrCopy(TblDesc.szTblType, szParadox);
// The optional parameters are passed in through the FLDDesc structure.
// It is possible to change many Options at one time by using a pointer
// to a FLDDesc (pFLDDesc) and allocating memory for the structure.
pFDesc.iOffset := 0;
pFDesc.iLen := Length(OptData) + 1;
StrPCopy(pFDesc.szName, Option);
// The changed values of the optional parameters are in a contiguous memory
// space. Sonce only one parameter is being used, the OptData variable
// can be used as a contiguous memory space.
TblDesc.iOptParams := 1; // Only one optional parameter
TblDesc.pFldOptParams := @pFDesc;
TblDesc.pOptData := @OptData[1];
try
// Restructure the table with the new parameter.
Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
finally
//Table.Open;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

table1.EmptyTable;

RestructureTable(Table1, 'LANGDRIVER', 'slovene'); // this is example how to change a table
language from PDOx 'intl' to PDOX 'slovene 852'

end;

Discussion


Log in to post a comment.