Hallo zusammen,
ich stehe aktuell auf dem Schlauch.
Die Sortierfunktion von TList gibt mir ein anderes Ergebnis bei einem 32bit Compilat wie bei einem 64bit Compilat.
Könnt ihr mir sagen warum?
Delphi 11, Windows 10 64bit
Delphi-Quellcode:
unit Unit3;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls, Math;
type
PMyStruct = ^TMyStruct;
TMyStruct =
packed record
Value1 : LongInt;
Value2 : Double;
Value3 : Byte;
function GetDataStr:
String;
end;
type
TForm3 =
class(TForm)
Memo1: TMemo;
Memo2: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
var
aList : TList;
aData : PMyStruct;
i: Integer;
function CompareItems(
const Item1,Item2: PMyStruct): Integer;
begin
Result := Math.CompareValue(Item1^.Value1, Item2^.Value1);
if Result <> 0
then
exit;
Result := Math.CompareValue(Item2^.Value2, Item1^.Value2);
if Result <> 0
then
exit;
Result := Math.CompareValue(Item1^.Value3, Item2^.Value3);
end;
begin
aList := TList.Create;
try
for i := 0
to 5
do
begin
New(aData);
aData^.Value1 := 1429078;
aData^.Value2 := 6.220;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 5
do
begin
New(aData);
aData^.Value1 := 1429079;
aData^.Value2 := 6.220;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 5
do
begin
New(aData);
aData^.Value1 := 1429080;
aData^.Value2 := 6.220;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 0
do
begin
New(aData);
aData^.Value1 := 1429081;
aData^.Value2 := 6.220;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 1
do
begin
New(aData);
aData^.Value1 := 1429081;
aData^.Value2 := 5.810;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 4
do
begin
New(aData);
aData^.Value1 := 1429082;
aData^.Value2 := 5.810;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 5
do
begin
New(aData);
aData^.Value1 := 1429083;
aData^.Value2 := 5.810;
aData^.Value3 := i;
aList.Add(aData);
end;
for i := 0
to 5
do
begin
New(aData);
aData^.Value1 := 1429084;
aData^.Value2 := 5.810;
aData^.Value3 := i;
aList.Add(aData);
end;
Memo1.Clear;
Memo1.Lines.Add('
VOR Sortierung');
for i := 0
to aList.Count - 1
do
begin
aData := aList.Items[i];
Memo1.Lines.Add('
(' + i.ToString +'
) - aData: ' + aData^.GetDataStr);
end;
aList.Sort(@CompareItems);
Memo2.Clear;
Memo2.Lines.Add('
NACH Sortierung');
for i := 0
to aList.Count - 1
do
begin
aData := aList.Items[i];
Memo2.Lines.Add('
(' + i.ToString +'
) - aData: ' + aData^.GetDataStr);
end;
finally
FreeAndNil(aList);
end;
end;
{ TMyStruct }
function TMyStruct.GetDataStr:
String;
begin
Result := Value1.ToString + '
/' + FloatToStrF(Value2, ffFixed, 15, 3) + '
/' + Value3.ToString;
end;
end.
Ergebnis nach Sortierung 32bit:
NACH Sortierung
(0) - aData: 1429078/6,220/0
(1) - aData: 1429078/6,220/1
(2) - aData: 1429078/6,220/2
(3) - aData: 1429078/6,220/3
(4) - aData: 1429078/6,220/4
(5) - aData: 1429078/6,220/5
(6) - aData: 1429079/6,220/0
(7) - aData: 1429079/6,220/1
(8) - aData: 1429079/6,220/2
(9) - aData: 1429079/6,220/3
(10) - aData: 1429079/6,220/4
(11) - aData: 1429079/6,220/5
(12) - aData: 1429080/6,220/0
(13) - aData: 1429080/6,220/1
(14) - aData: 1429080/6,220/2
(15) - aData: 1429080/6,220/3
(16) - aData: 1429080/6,220/4
(17) - aData: 1429080/6,220/5
(18) - aData: 1429081/6,220/0
(19) - aData: 1429081/5,810/0
(20) - aData: 1429081/5,810/1
(21) - aData: 1429082/5,810/0
(22) - aData: 1429082/5,810/1
(23) - aData: 1429082/5,810/2
(24) - aData: 1429082/5,810/3
(25) - aData: 1429082/5,810/4
(26) - aData: 1429083/5,810/0
(27) - aData: 1429083/5,810/1
(28) - aData: 1429083/5,810/2
(29) - aData: 1429083/5,810/3
(30) - aData: 1429083/5,810/4
(31) - aData: 1429083/5,810/5
(32) - aData: 1429084/5,810/0
(33) - aData: 1429084/5,810/1
(34) - aData: 1429084/5,810/2
(35) - aData: 1429084/5,810/3
(36) - aData: 1429084/5,810/4
(37) - aData: 1429084/5,810/5
Ergebnis nach Sortierung 64bit:
NACH Sortierung
(0) - aData: 1429082/5,810/3
(1) - aData: 1429082/5,810/4
(2) - aData: 1429083/5,810/0
(3) - aData: 1429083/5,810/1
(4) - aData: 1429082/5,810/2
(5) - aData: 1429081/5,810/0
(6) - aData: 1429081/5,810/1
(7) - aData: 1429082/5,810/0
(8) - aData: 1429082/5,810/1
(9) - aData: 1429083/5,810/2
(10) - aData: 1429084/5,810/2
(11) - aData: 1429084/5,810/3
(12) - aData: 1429084/5,810/4
(13) - aData: 1429084/5,810/5
(14) - aData: 1429084/5,810/1
(15) - aData: 1429083/5,810/3
(16) - aData: 1429083/5,810/4
(17) - aData: 1429083/5,810/5
(18) - aData: 1429084/5,810/0
(19) - aData: 1429078/6,220/5
(20) - aData: 1429079/6,220/0
(21) - aData: 1429079/6,220/1
(22) - aData: 1429079/6,220/2
(23) - aData: 1429078/6,220/4
(24) - aData: 1429078/6,220/0
(25) - aData: 1429078/6,220/1
(26) - aData: 1429078/6,220/2
(27) - aData: 1429078/6,220/3
(28) - aData: 1429079/6,220/3
(29) - aData: 1429080/6,220/3
(30) - aData: 1429080/6,220/4
(31) - aData: 1429080/6,220/5
(32) - aData: 1429081/6,220/0
(33) - aData: 1429080/6,220/2
(34) - aData: 1429079/6,220/4
(35) - aData: 1429079/6,220/5
(36) - aData: 1429080/6,220/0
(37) - aData: 1429080/6,220/1
Anmerkung:
Erste Durchlauf von "Result := Math.CompareValue(Item1^.Value1, Item2^.Value1);" unter 32bit ist
Item1^.Value1 -> 1429078
und
Item2^.Value1 -> 1429081
Erste Durchlauf von "Result := Math.CompareValue(Item1^.Value1, Item2^.Value1);" unter 64bit ist
Item1^.Value1 -> 1429081
und
Item2^.Value1 -> 1429081
Das heißt, die Liste selber ruft meine Comparefunktion schon unterschiedlich auf...