Stworzyłem sobie dll do skryptu ponieważ nie obsługuje on takich funkcji. Ale wywala mi taki błąd.
main.pas(38:2) [TEST]: In unit main.pas(38:2): Exception: Privileged instruction
unit Test_Sort;
interface
function Sort_TStringList_By_Values(Data_To_Sort: TStringList): TStringList;
external 'Sort_TStringList_By_Values@sort.dll';
implementation
procedure Test();
var i: byte; Data, Data_2: TStringList;
begin
Data := File.CreateStringList;
Data_2 := File.CreateStringList;
Data.Sorted := false;
Data.Values['Kolos'] := '1';
Data.Values['`Defektalios!22'] := '10';
Data.Values['Kajtek'] := '2';
Data.Values['Paulcia'] := '1680';
Data.Values['Ktoś taki'] := '440';
Data.Values['WujekJędrzej'] := '1900';
Data.Values['SuperMan'] := '450';
Data.Values['Fajki'] := '650';
Data.Values['Polinka'] := '1690';
Data.Values['Dupek'] := '20';
Data.Values['Nacia'] := '680';
for i := 0 to 10 do WriteLn(Data.Strings[i]);
writeLN(' ');
writeLN(' ');
writeLN(' ');
Data_2 := Sort_TStringList_By_Values(Data);
for i := 0 to 10 do WriteLn(Data.Strings[i]);
Data.Free;
Data_2.Free;
end;
initialization
begin
Test();
end;
end.
library Sort_By_Values;
{$mode objfpc}{$H+}
uses
SysUtils, Classes;
function StringListSortProc(List: TStringList; Index1, Index2: Integer): Integer;
var i1, i2: Integer;
begin
i1 := StrToInt(List.ValueFromIndex[Index1]);
i2 := StrToInt(List.ValueFromIndex[Index2]);
Result := i1 - i2;
end;
function Sort_TStringList_By_Values(Data_To_Sort: TStringList): TStringList;
begin
Data_To_Sort.CustomSort(@StringListSortProc);
Result := Data_To_Sort;
end;
exports
Sort_TStringList_By_Values;
begin
end.