Title: Sort a table with BDE calls
Question: How sort a table with BDE calls?
Answer:
Most of us, well those that them interests the data bases, know as ordering a simple table, for this exist different methods, to use a Query (TQUERY) with a sentence SELECT, maybe to use indices on the field that is wished to order, inclusive to change them in execution time.
Here humbly I present an other form of ordering a table, through calls to the BDE, this can practically to limit its use to Xbase tables (Paradox, dBase, Fox...)
1.Create a procedure that it will be equals to the following and introduces the appropriate code.
procedure SortTable(Db: TDatabase; SortTable:TTable; const NumSortFields: array of Word;
const Caseinsensitive: array of Bool;
const SortOrd: array of SORTOrder;
RemoveDuplicate: Boolean);
// Db Database that contains table to sort.
// SortTable Table sorted.
// NumSortFields Numberes of fieldes to sort on.
// Caseinsensitive :)
// SortOrd :)
// RemoveDuplicate Delete duplicate records.
var
hDB: hDBIdb; {Handle of database holding tbl.}
pTblName: array[0..DBIMAXPATHLEN] of char; {Table name.}
NumRecs: LongInt; {Number of records to sort.}
SortFldCount: Word; {Number of fields to sort on.}
begin
hDb := Db.Handle;
StrPCopy(pTblName, SortTable.TableName);
SortFldCount := High(NumSortFields) + 1;
Check(DBISortTable(hDB, pTblName, szPARADOX,
nil, nil, nil,
nil, SortFldCount, @NumSortFields,
@Caseinsensitive, @SortOrd, nil,
RemoveDuplicate, nil, NumRecs));
end;
2. Due to the fact that the parameters and the calls can result a little strange. Below I explain the form of calling. The data base (TDataBase) must be connected.
3. Table (TTable) must be closed.
4. If are not fulfilled the previous two conditions the call generated an exception.
5. Create a similar procedure to the following.
procedure CallSort;
var
SortFields: array[0..1] of Word;
SortCase: array[0..1] of Bool;
SortOrd: array[0..1] of SORTOrder;
begin
Table1.Active := False;
SortFields[0] := 1;
SortFields[1] := 2;
SortCase[0] := True;
SortCase[1] := True;
SortOrd[0] := sortASCEND;
SortOrd[1] := sortDESCEND;
dgSortTable(Database1, Table1, SortFields,
SortCase, SortOrd, False);
Table1.Active := True;
end;
6. Observe that here we do not make mention to the name of the field, only we referred ourselves to him through its position in table.
A greeting.