I have a delphi application that uses tdbf which is based on tdataset with the advantage of not requiring bde engine. I needed the table to be sorted and I did this one a single field by adding an indexdef and then specifying the indexfieldnames.
I am trying to now get it to sort on 2 fields ie group men together and then women together and then have each group sorted on salary so that we see females from lowest earner to highest earner followed by men in the same way.
I have read every piece of material stating that you simply specify sortfield of the indexdef as 'gender+salary'. When I try use the index I get told that '+' is not a valid fieldname. I have tried every delimeter from '.'. ','. '&' and ';'. Every delimeter gets picked up as a field that doesn't exist. What is the correct way to sort a table on multiple fields?
Thanks in advance Clinton Brits
xBASE
(dBASE and it's derivatives) requires that fields in an index all be converted to the same data type, typically strings. To do that typically requires some common functions:CCYYMMDD
as a stringSTR(<numeric> [, <width> [, <decimaldigits>] ])
.IIF(Married = .T., 'Y', 'N')
Index expressions are indeed combined with the
+
operator. The error you're receiving is probably because you haven't converted to a common data type.As you've specified the
Gender
column (probably defined asCHAR 1
) andSalary
column (probably aNUMERIC
of some size), you can use something likeThis creates a index on an expression like
F 10000
,F 200000
,M 12000
, whereSALARY
is converted to the default width of 10 characters (left padded with spaces) and no decimal digits. This should work for you.