Hi All,
I'm trying to get started with records. I have read a number of things dealing with sorting an array of them,
but nothing at the simplistic level I need. The sorting I have in mind keeps the record fields together -- once a sorting field is chosen, all the fields adopt the same index. Offering the following flawed snippit. Trying to get the following output:
arp 0.21 2
arp 0.34 3
arp 0.501 1
arp 0.77 0
type
TPair = Record
sjac : Double;
indexx : Integer;
end;
procedure Tform1.FillRecords(Sender: TObject);
var r : Integer;
begin
arp[0].sjac := 0.34; arp[0].indexx := 3;
arp[1].sjac := 0.77; arp[1].indexx := 0;
arp[2].sjac := 0.21; arp[2].indexx := 2;
arp[3].sjac := 0.501; arp[3].indexx := 1;
SortRecords(Sender);
for r := 0 to 3 do
output.Add( 'arp ' + FloattoStr(arp[r].sjac) + ' ' + InttoStr(arp[r].indexx));
end;
procedure TForm1.SortRecords(Sender: TObject);
var
p, q : Integer;
index : Double;
begin
for p := 0 to 3 do
begin
index := arp[p].sjac;
q := p;
while ((q > 0) AND (arp[q-1].sjac > index)) do
begin
arp[q].sjac := arp[q-1].sjac;
{arp[q].indexx := arp[q-1].indexx; **this line only does half of them}
q := q - 1;
end;
arp[q].sjac:= index;
end;
end;