I created a CustomSort for a list with TStringLinst. On Windows works fine, but on Android List
object is sent as nil
to the CompareDatesReverse
function. In the documentation there is no any difference between the operating systems to this function.
Is there any different handling for the CustomSort function on Android?
Parameter List = nil
in the CompareDatesReverse
function on Android => Error: Exception class Segmentation fault (11)
TObjAux = class(TObject)
FileAge: TDateTime;
Path: String;
end;
procedure TForm1.Button1Click(Sender: TObject);
function CompareDatesReverse(List: TStringList; Index1, Index2: Integer): Integer;
var d1, d2: TDateTime;
begin
d1 := TObjAux(List.Objects[Index1]).FileAge; // List = Nil on Android
d2 := TObjAux(List.Objects[Index2]).FileAge;
if d1 > d2 then
Result := -1
else if d1 < d2 then
Result := 1
else
Result := 0;
end;
var
LList: TStringDynArray;
i: Integer;
fls: TStringList;
vTmp: String;
ObjAux: TObjAux;
begin
fls := TStringList.Create;
fls.Clear;
vTmp := TPath.GetDocumentsPath;
LList := TDirectory.GetFiles(vTmp);
for i := 0 to Length(LList) - 1 do begin
ObjAux := TObjAux.Create;
ObjAux.Path := LList[i];
FileAge(LList[i], ObjAux.FileAge);
fls.AddObject(FloatToStr(ObjAux.FileAge), ObjAux);
end;
if fls.Count > 0 then fls.CustomSort(@CompareDatesReverse);
fls.DisposeOf;
end;