Example of Sorted Variable Fields or Records

The following example shows the use of the extractSort method to sort variable-length fields or records.

variableTest();
vars
    saa                    : SortActorArray;
    sortActor1, sortActor2 : SortActor;
    file                   : File;
begin
    create file transient;
    create saa transient;
    create sortActor1 transient;
    create sortActor2 transient;
    file.recordSize := 0; // Variable length records
    file.endOfLine := CrLf; // <cr><lf> record delimiter
    file.endOfField := ","; // Comma-delimited fields
    file.fileName := "c:\test\temp.txt";
    file.allowReplace := true; // Replace the source file
    // The first actor
    sortActor1.sortType := SortActor.SortType_String; // Invoke alphanumeric
    sortActor1.length := 8; // sort of length 8
    sortActor1.startPosition := 10; // Start at position 10
    sortActor1.fieldNo := 1; // of the first field
    sortActor1.ascending := true; // Ascending sort order
    sortActor1.random := false; // Not random order
    // The second actor
    sortActor2.sortType := SortActor.SortType_String; // Invoke alphanumeric
    sortActor2.length := 8; // sort of length 8
    sortActor2.startPosition := 1; // Start at position 1
    sortActor2.fieldNo := 2; // of the second field
    sortActor2.ascending := false; // Descending sort order
    saa[1] := sortActor1;
    saa[2] := sortActor2;
    file.extractSort(saa, file); // Sort the file now
epilog
    delete file;
    delete saa;
    delete sortActor1;
    delete sortActor2;
end;