Board index » delphi » SORTING RECORDS-NON TEXT FILES

SORTING RECORDS-NON TEXT FILES

Hello
I have written a program using a text file to update a soccer
league . I can sort this ARRAY quite easily once the results
have been entered.

However, I have decided to write a non-text file containing
a FILE OF declaration and corresponding VAR but now I am
LOST regarding the SORTING of the RECORD. As per normal
I need to sort first by points, then IF NECESSARY, by
goal difference, then by goals For etc.

My RECORD has been declared as follows:
TeamRecord = RECORD
             TeamName : STRING[25];
             Played,Won,Drawn,Lost,GoalsFor,GoalsAgainst,
             GoalDifference,Points     : INTEGER;
VAR
      TeamCall : TeamRecord;

My code allows me already to enter results and update the records
accordingly with the necessary adjustments to Won, Drawn, Points
etc.
NOW I NEED TO SORT
PLEASE HELP

lbrea...@ilink.nis.za
Lawrence Breakey
Cape Town, South Africa

 

Re:SORTING RECORDS-NON TEXT FILES


How does one SORT Records in a Non-Text File. (The text
file's was fairly simple)

I am working on asoccer league table and have written code
to adjust all data once results have been entered.

Primary Key field = Points , then sorting via goal difference
and then goals for if necessary.

My declaration:

TeamRecord = RECORD Played,Won,Drawn,Lost,GoalsFor,GoalsAgainst,
GoalDifference,Points   : INTEGER;
TeamName: STRING[25];
END;
VAR
   TeamCall : TeamRecord

Please help
Lawrence Breakey
lbrea...@ilink.nis.za

Re:SORTING RECORDS-NON TEXT FILES


On 6 Dec 1996 21:47:47 GMT,  lbrea...@ilink.nis.za (lawrence noel

Quote
breakey) wrote:
>However, I have decided to write a non-text file containing
>a FILE OF declaration and corresponding VAR but now I am
>LOST regarding the SORTING of the RECORD. As per normal
>I need to sort first by points, then IF NECESSARY, by
>goal difference, then by goals For etc.

>My RECORD has been declared as follows:
>TeamRecord = RECORD
>             TeamName : STRING[25];
>             Played,Won,Drawn,Lost,GoalsFor,GoalsAgainst,
>             GoalDifference,Points     : INTEGER;

Create a comparison function that returns -1, 0, +1 depending whether
the first item is smaller, equal, or larger than the second.  With
that in mind you should be able to modify your existing sort
accordingly.

Example:
FUNCTION Compare(const A, B: TeamRecord): Integer;
VAR i: Integer;
BEGIN
    i := SignOf(A.Points - B.Points);
    If i = 0 Then i := Sigeof(....

    Compare := i;    
END;

Once you fill in the rest of the function and implement an appropriate
SignOf function, you should be in business.

    ...red

Other Threads