How to sort CSV file in TTable?

I have a TTable, and I'm uploading CSV files to this TTable. Three fields: Id, Hits and Path. I made several search fields for this TTable with another query.

I want to sort a table. I get the message "Features not supported." when i try to callAddIndex('ndxHits','HITS',[]);

Here is my code:

with DM.TblCVResults do
begin
  try
    Active     :=  False;
    TableName  :=  'C:\CSV\123.txt';
    Active     :=  True;

    AddIndex('ndxHits','HITS',[]);
    AddIndex('ndxCandidate','LkCandidate',[]);
    AddIndex('ndxLastCV','LkLastCV',[]);
    AddIndex('ndxPostCode','LkPostCode',[]);
    IndexDefs.Update;
    Active     :=  True;
    DM.TblCVResults.IndexName := 'ndxHits';
  except
    on E: Exception do
      MsgError(E.Message);
  end;
end
+3
source share
1 answer

In the previous previous question, you used ttASCIIhow TableType. ttASCIItables, AFAIK, do not support indexes.

It is best to load content ttASCII TTableinto TClientDataset` (CDS), which supports indexes. I have not tested the ttASCII table as a source, but it should be as simple as:

TDatasetProvider. DataSet TTable.

TClientDataSet. ProviderName DataSetProvider, . ( CDS .)

Table ClientDataSet (CDS) .

Table1.Active := True;
CDS.Active := True;

TTable, . ( .)

CDS.LogChanges := False;

:

// Repeat for each additional index
with CDS.IndexDefs.AddIndexDef do
begin
  Name := 'ndxHits';
  Fields := 'Hits';
  Options := [];
end;

ClientDataSet's IndexName , :

CDS.IndexName := 'ndxHits';

ClientDataSet, . Locate FindKey, Insert Append, ..

+7

Source: https://habr.com/ru/post/1782582/


All Articles