Advertisement
Janilabo

Janilabo | integer_.dpr [SCAR Divi]

May 29th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 45.12 KB | None | 0 0
  1. library integer_;
  2.  
  3. uses
  4.   FastShareMem,
  5.   SysUtils,
  6.   Math;
  7.  
  8. {$R *.res}
  9.  
  10. type
  11.   MSSL_TControlMethod = (cm_None, cm_Filter, cm_Extract);
  12.   MSSL_TPartitionMethod = (pm_PartSize, pm_PartAmount);
  13.   TIntegerArray = array of Integer;
  14.   TIntArray = TIntegerArray;
  15.   T2DIntegerArray = array of TIntegerArray;
  16.   T2DIntArray = T2DIntegerArray;
  17.  
  18. function TIAContains(TIA: TIntArray; x: Integer): Boolean;
  19. var
  20.   h, i: Integer;
  21. begin
  22.   h := High(TIA);
  23.   for i := 0 to h do
  24.     if (TIA[i] = x) then
  25.       Break;
  26.   Result := ((h > -1) and (i <= h));
  27. end;
  28.  
  29. procedure TIARemoveEx(var TIA: TIntArray; x: Integer; all: Boolean);
  30. var
  31.   h, i, d: Integer;
  32. begin
  33.   h := High(TIA);
  34.   if (h > -1) then
  35.   begin
  36.     case all of
  37.       True:      
  38.       for i := h downto 0 do
  39.         if (TIA[i] = x) then
  40.         begin
  41.           for d := i to (h - 1) do
  42.             TIA[d] := TIA[(d + 1)];
  43.           Dec(h);
  44.         end;
  45.       False:
  46.       for i := 0 to h do
  47.         if (TIA[i] = x) then
  48.         begin
  49.           for d := i to (h - 1) do
  50.             TIA[d] := TIA[(d + 1)];
  51.           Dec(h);
  52.           Break;      
  53.         end;
  54.     end;
  55.     SetLength(TIA, (h + 1));
  56.   end;
  57. end;
  58.  
  59. {==============================================================================]  
  60.   Explanation: Returns a TIA that contains all the value from start value (aStart)
  61.                to finishing value (aFinish)..
  62. [==============================================================================}
  63. function MSSL_TIAByRange(aStart, aFinish: Integer): TIntArray; stdcall;
  64. var
  65.   i, s, f: Integer;
  66. begin
  67.   if (aStart <> aFinish) then
  68.   begin
  69.     s := Integer(aStart);
  70.     f := Integer(aFinish);
  71.     SetLength(Result, (Abs(aStart - aFinish) + 1));
  72.     case (aStart > aFinish) of
  73.       True:
  74.       for i := s downto f do
  75.         Result[(s - i)] := i;
  76.       False:
  77.       for i := s to f do
  78.         Result[(i - s)] := i;
  79.     end;
  80.   end else
  81.   begin
  82.     SetLength(Result, 1);
  83.     Result[0] := Integer(aStart);
  84.   end;
  85. end;
  86.  
  87. {==============================================================================]
  88.   Explanation: Returns a TIA that contains all the value from start value (aStart)
  89.                to finishing value (aFinish)..
  90.                Works with 2-bit method, that cuts loop in half.
  91. [==============================================================================}
  92. function MSSL_TIAByRange2bit(aStart, aFinish: Integer): TIntArray; stdcall;
  93. var
  94.   g, l, i, s, f: Integer;
  95. begin
  96.   if (aStart <> aFinish) then
  97.   begin
  98.     s := Integer(aStart);
  99.     f := Integer(aFinish);
  100.     l := (Abs(aStart - aFinish) + 1);            
  101.     SetLength(Result, l);    
  102.     g := ((l - 1) div 2);  
  103.     case (aStart < aFinish) of
  104.       True:
  105.       begin
  106.         for i := 0 to g do
  107.         begin                      
  108.           Result[i] := (s + i);
  109.           Result[((l - 1) - i)] := (f - i);
  110.         end;
  111.         if ((l mod 2) <> 0) then
  112.           Result[i] := (s + i);  
  113.       end;
  114.       False:
  115.       begin
  116.         for i := 0 to g do
  117.         begin                      
  118.           Result[i] := (s - i);
  119.           Result[((l - 1) - i)] := (f + i);
  120.         end;
  121.         if ((l mod 2) <> 0) then
  122.           Result[i] := (s - i);  
  123.       end;  
  124.     end;    
  125.   end else
  126.   begin
  127.     SetLength(Result, 1);
  128.     Result[0] := Integer(aStart);
  129.   end;
  130. end;
  131.  
  132. {==============================================================================]
  133.   Explanation: Returns array of x, count being the size of the result.
  134. [==============================================================================}
  135. function MSSL_TIAOfInteger(x, count: Integer): TIntArray; stdcall;
  136. var
  137.   i: Integer;
  138. begin
  139.   if (count > 0) then
  140.   begin
  141.     SetLength(Result, count);
  142.     for i := 0 to (count - 1) do
  143.       Result[i] := Integer(x);
  144.   end else
  145.     SetLength(Result, 0);
  146. end;
  147.  
  148. {==============================================================================]
  149.   Explanation: Converts integer value (int) to digits of it.
  150.   Example: 1234 => 1,2,3,4
  151. [==============================================================================}
  152. function MSSL_IntDigits(int: Integer): TIntArray; stdcall;
  153. var
  154.   s: string;
  155.   l, i: Integer;
  156. begin
  157.   s := IntToStr(Abs(int));
  158.   l := Length(s);
  159.   SetLength(Result, l);
  160.   for i := 0 to (l - 1) do
  161.     Result[i] := StrToInt(s[(i + 1)]);
  162. end;
  163.  
  164. {==============================================================================]
  165.   Explanation: Returns true if str is integer value.
  166. [==============================================================================}
  167. function MSSL_StrIsInt(str: string): Boolean; stdcall;
  168. begin
  169.   try
  170.     StrToInt(str);
  171.     Result := True;
  172.   except
  173.     Result := False;
  174.   end;
  175. end;
  176.  
  177. {==============================================================================]
  178.   Explanation: Sets minimum value (x) to val.
  179. [==============================================================================}
  180. procedure MSSL_IntSetMin(var val: Integer; x: Integer); stdcall;
  181. begin
  182.   if (val < x) then
  183.     val := Integer(x);
  184. end;
  185.  
  186. {==============================================================================]
  187.   Explanation: Sets maximum value (x) to val.
  188. [==============================================================================}
  189. procedure MSSL_IntSetMax(var val: Integer; x: Integer); stdcall;
  190. begin
  191.   if (val > x) then
  192.     val := Integer(x);
  193. end;
  194.  
  195. {==============================================================================]
  196.   Explanation: Sets val inside range (mn = minimum, mx = maximum)
  197. [==============================================================================}
  198. procedure MSSL_IntSetRange(var val: Integer; mn, mx: Integer); stdcall;
  199. var
  200.   t: Integer;
  201. begin
  202.   if (mn > mx) then
  203.   begin
  204.     t := mn;
  205.     mn := mx;
  206.     mx := t;
  207.   end;
  208.   if (mn <> mx) then
  209.   begin        
  210.     if (val < mn) then
  211.       val := Integer(mn);
  212.     if (val > mx) then
  213.       val := Integer(mx);
  214.   end else    
  215.     if ((val < mn) or (val > mx)) then
  216.       val := Integer(mn);
  217. end;
  218.  
  219. {==============================================================================]
  220.   Explanation: Sets minimum value (x) to TIA items.
  221. [==============================================================================}
  222. procedure MSSL_TIASetMin(var TIA: TIntArray; x: Integer); stdcall;
  223. var
  224.   h, i: Integer;
  225. begin
  226.   h := High(TIA);
  227.   for i := 0 to h do
  228.     if (TIA[i] < x) then
  229.       TIA[i] := Integer(x);
  230. end;
  231.  
  232. {==============================================================================]
  233.   Explanation: Sets maximum value (x) to TIA items.
  234. [==============================================================================}
  235. procedure MSSL_TIASetMax(var TIA: TIntArray; x: Integer); stdcall;
  236. var
  237.   h, i: Integer;
  238. begin
  239.   h := High(TIA);
  240.   for i := 0 to h do
  241.     if (TIA[i] > x) then
  242.       TIA[i] := Integer(x);
  243. end;
  244.  
  245. {==============================================================================]
  246.   Explanation: Sets TIA values inside range (mn = minimum, mx = maximum)
  247. [==============================================================================}
  248. procedure MSSL_TIASetRange(var TIA: TIntArray; mn, mx: Integer); stdcall;
  249. var
  250.   h, i, t: Integer;
  251. begin
  252.   if (mn > mx) then
  253.   begin
  254.     t := mn;
  255.     mn := mx;
  256.     mx := t;
  257.   end;
  258.   h := High(TIA);
  259.   if (h > -1) then
  260.   case (mn = mx) of
  261.     True:
  262.     for i := 0 to h do
  263.       if ((TIA[i] < mn) or (TIA[i] > mx)) then
  264.         TIA[i] := Integer(mn);
  265.     False:
  266.     for i := 0 to h do
  267.     begin
  268.       if (TIA[i] < mn) then
  269.         TIA[i] := Integer(mn);
  270.       if (TIA[i] > mx) then
  271.         TIA[i] := Integer(mx);
  272.     end;    
  273.   end;
  274. end;
  275.  
  276. {==============================================================================]
  277.   Explanation: Control's TIA by range. Contains actions for 2 methods: cm_Filter and cm_Extract.
  278. [==============================================================================}
  279. procedure MSSL_TIAControlByRange(var TIA: TIntArray; minimum, maximum: Integer; method: MSSL_TControlMethod); stdcall;
  280. var
  281.   h, i, l, v: Integer;
  282. begin
  283.   h := High(TIA);
  284.   if ((minimum <= maximum) and (h > -1) and (method <> cm_None)) then
  285.   case method of
  286.     cm_Filter:
  287.     for i := h downto 0 do
  288.       if ((TIA[i] >= minimum) and (TIA[i] <= maximum)) then
  289.       begin
  290.         l := Length(TIA);
  291.         for v := i to (l - 2) do
  292.           TIA[v] := TIA[(v + 1)];
  293.         SetLength(TIA, (l - 1));
  294.       end;
  295.     cm_Extract:
  296.     for i := h downto 0 do
  297.       if ((TIA[i] < minimum) or (TIA[i] > maximum)) then
  298.       begin
  299.         l := Length(TIA);
  300.         for v := i to (l - 2) do
  301.           TIA[v] := TIA[(v + 1)];
  302.         SetLength(TIA, (l - 1));
  303.       end;
  304.   end;
  305. end;
  306.  
  307. {==============================================================================]
  308.   Explanation: Returns true if TIA is built ONLY with allowed values.
  309. [==============================================================================}
  310. function MSSL_TIABuiltWith(TIA, allowed: TIntArray): Boolean; stdcall;
  311. var
  312.   h, l, i, v: Integer;
  313. begin
  314.   Result := False;
  315.   l := Length(TIA);
  316.   h := High(allowed);
  317.   if ((h > -1) and (l > 0)) then
  318.   begin
  319.     for i := 0 to h do
  320.     begin
  321.       for v := 0 to (l - 1) do
  322.         if (TIA[v] = allowed[i]) then
  323.           Break;
  324.       if (v >= l) then
  325.         Exit;
  326.     end;
  327.     Result := True;
  328.   end;
  329. end;
  330.  
  331. {==============================================================================]
  332.   Explanation: Randomizes TIA.
  333.                Example: [1, 2, 3] => [2, 3, 1]
  334.                The higher count of shuffles is, the "stronger" randomization you'll get.
  335. [==============================================================================}
  336. procedure MSSL_TIARandomizeEx(var TIA: TIntArray; shuffles: Integer); stdcall;
  337. var
  338.   a, b, l, i, t, v: Integer;
  339. begin
  340.   l := Length(TIA);
  341.   if ((l > 1) and (shuffles > 0)) then
  342.     for t := 1 to shuffles do
  343.       for i := 0 to (l - 1) do
  344.       begin
  345.         a := Random(l);
  346.         b := Random(l);
  347.         if (a <> b) then
  348.         begin
  349.           v := TIA[a];
  350.           TIA[a] := TIA[b];
  351.           TIA[b] := v;
  352.         end;
  353.       end;
  354. end;
  355.  
  356. {==============================================================================]
  357.   Explanation: Randomizes TIA.
  358.                Example: [1, 2, 3] => [2, 3, 1]
  359. [==============================================================================}
  360. procedure MSSL_TIARandomize(var TIA: TIntArray); stdcall;
  361. begin
  362.   MSSL_TIARandomizeEx(TIA, 1);
  363. end;
  364.  
  365. {==============================================================================]
  366.   Explanation: Deletes item with index (x) from TIA. Returns true with success.
  367. [==============================================================================}
  368. function MSSL_TIADelete(var TIA: TIntArray; x: Integer): Boolean; stdcall;
  369. var
  370.   h, i, v: Integer;
  371. begin
  372.   h := High(TIA);
  373.   Result := ((x <= h) and (x > -1));
  374.   if Result then
  375.   begin
  376.     for i := v to (h - 1) do
  377.       TIA[i] := TIA[(i + 1)];
  378.     SetLength(TIA, h);
  379.   end;
  380. end;
  381.  
  382. {==============================================================================]
  383.   Explanation: Removes integers from TIA, x = array of indexes.
  384. [==============================================================================}
  385. procedure MSSL_TIARemove(var TIA: TIntArray; x: TIntArray); stdcall;
  386. var
  387.   i, h, h2, v: Integer;
  388. begin
  389.   h := High(TIA);
  390.   h2 := High(x);
  391.   if ((h > -1) and (h2 > -1)) then
  392.     for i := 0 to h2 do
  393.       if ((x[i] <= h) and (x[i] > -1)) then
  394.       begin
  395.         for v := x[i] to (h - 1) do
  396.           TIA[v] := TIA[(v + 1)];
  397.         SetLength(TIA, h);
  398.         Dec(h);
  399.       end;
  400. end;
  401.  
  402. {==============================================================================]
  403.   Explanation: Adds all addTIA items to TIA. Returns the highest index in the end.
  404. [==============================================================================}
  405. function MSSL_TIAAdd(var TIA: TIntArray; addTIA: TIntArray): Integer; stdcall;
  406. var
  407.   h, l, i: Integer;
  408. begin
  409.   h := High(addTIA);
  410.   if (h > -1) then
  411.   begin
  412.     l := Length(TIA);
  413.     SetLength(TIA, (l + (h + 1)));
  414.     for i := 0 to h do
  415.       TIA[(i + l)] := Integer(addTIA[i]);
  416.   end;
  417.   Result := High(TIA);
  418. end;
  419.  
  420. {==============================================================================]
  421.   Explanation: Returns all the TIA positions where x can be found.
  422. [==============================================================================}
  423. function MSSL_TIAPositions(TIA: TIntArray; x: Integer): TIntArray; stdcall;
  424. var
  425.   i, h, r: Integer;
  426. begin
  427.   h := High(TIA);          
  428.   if (h > -1) then
  429.   begin
  430.     SetLength(Result, (h + 1));
  431.     for i := 0 to h do
  432.       if (TIA[i] = x) then
  433.       begin
  434.         Result[r] := i;
  435.         Inc(r);
  436.       end;  
  437.   end;
  438.   SetLength(Result, r);
  439. end;
  440.  
  441. {==============================================================================]
  442.   Explanation: Returns the TIA positions where index contains any integer from ints.
  443.   NOTE: Doesn't return ALL indexes, like MSSL_TIAPositionsEx() does.
  444. [==============================================================================}
  445. function MSSL_TIAPositionsMulti(TIA, ints: TIntArray): TIntArray; stdcall;
  446. var
  447.   a, b, i, h: Integer;
  448. begin
  449.   h := High(ints);
  450.   b := High(TIA);
  451.   if ((b > -1) and (h > -1)) then
  452.   begin
  453.     SetLength(Result, (h + 1));
  454.     for i := 0 to h do
  455.     begin
  456.       Result[i] := -1;
  457.       for a := 0 to b do
  458.         if (TIA[a] = ints[i]) then
  459.         begin
  460.           Result[i] := a;
  461.           Break;
  462.         end;
  463.     end;
  464.   end else
  465.     SetLength(Result, 0);
  466. end;
  467.  
  468. {==============================================================================]
  469.   Explanation: Returns all the TIA positions where index contains any integer from ints.
  470. [==============================================================================}
  471. function MSSL_TIAPositionsEx(TIA, ints: TIntArray): TIntArray; stdcall;
  472. var
  473.   i, h, r, l, v: Integer;
  474. begin
  475.   h := High(TIA);
  476.   l := Length(ints);
  477.   if ((l > 0) and (h > -1)) then
  478.   begin
  479.     SetLength(Result, (h + 1));
  480.     for i := 0 to h do
  481.     begin
  482.       for v := 0 to (l - 1) do
  483.         if (ints[v] = TIA[i]) then
  484.           Break;
  485.       if (v < l) then
  486.       begin
  487.         Result[r] := i;
  488.         Inc(r);
  489.       end;
  490.     end;
  491.   end;
  492.   SetLength(Result, r);
  493. end;
  494.  
  495. {==============================================================================]
  496.   Explanation: Copies TIA from pos1 to pos2.
  497. [==============================================================================}
  498. function MSSL_TIACopyEx(TIA: TIntArray; pos1, pos2: Integer): TIntArray; stdcall;
  499. var
  500.   i, l: Integer;
  501. begin
  502.   l := Length(TIA);
  503.   if (l > 0) then
  504.   begin  
  505.     MSSL_IntSetRange(pos1, 0, (l - 1));
  506.     MSSL_IntSetRange(pos2, 0, (l - 1));
  507.     case (pos1 <> pos2) of
  508.       True:
  509.       begin
  510.         SetLength(Result, (Abs(pos1 - pos2) + 1));
  511.         case (pos1 < pos2) of            
  512.           True:
  513.           for i := pos1 to pos2 do
  514.             Result[(i - pos1)] := Integer(TIA[i]);
  515.           False:
  516.           for i := pos1 downto pos2 do
  517.             Result[(pos1 - i)] := Integer(TIA[i]);  
  518.         end;
  519.       end;
  520.       False:
  521.       begin
  522.         SetLength(Result, 1);
  523.         Result[0] := Integer(TIA[pos1]);
  524.       end;
  525.     end;
  526.   end else
  527.     SetLength(Result, 0);
  528. end;
  529.  
  530. {==============================================================================]
  531.   Explanation: Moves oldIndex to newIndex in TIA. Returns true, if movement was succesfully done!
  532. [==============================================================================}
  533. function MSSL_TIAMove(var TIA: TIntArray; oldIndex, newIndex: Integer): Boolean; stdcall;
  534. var
  535.   h, i, t: Integer;
  536. begin
  537.   h := High(TIA);
  538.   Result := ((h > 0) and (oldIndex <> newIndex) and InRange(oldIndex, 0, h) and InRange(newIndex, 0, h));
  539.   if Result then
  540.   case (oldIndex > newIndex) of
  541.     True:
  542.     for i := oldIndex downto (newIndex + 1) do
  543.     begin
  544.       t := TIA[i];
  545.       TIA[i] := TIA[(i - 1)];
  546.       TIA[(i - 1)] := t;
  547.     end;
  548.     False:
  549.     for i := oldIndex to (newIndex - 1) do
  550.     begin
  551.       t := TIA[i];
  552.       TIA[i] := TIA[(i + 1)];
  553.       TIA[(i + 1)] := t;
  554.     end;
  555.   end;
  556. end;
  557.  
  558. {==============================================================================]
  559.   Explanation: Breaks TIA to parts (TIA => ATIA). Contains 2 methods:
  560.                -pm_PartSize (Breaks TIA to ATIA by size of the parts) [x = size]
  561.                -pm_PartAmount (Breaks TIA to ATIA by amount of the parts) [x = amount]
  562. [==============================================================================}
  563. function MSSL_TIAToParts(TIA: TIntArray; method: MSSL_TPartitionMethod; x: Integer): T2DIntArray; stdcall;
  564. var
  565.   a, e, h, h2, i, i2, p, l, z: Integer;
  566.   f: Boolean;
  567. begin
  568.   h := High(TIA);
  569.   case ((h > -1) and (x > 0)) of
  570.     True:
  571.     begin
  572.       case method of
  573.         pm_PartSize:
  574.         if (x <= h) then
  575.         begin
  576.           Inc(h);
  577.           p := (h div x);
  578.           if ((p * x) < h) then
  579.             Inc(p);
  580.           SetLength(Result, p);
  581.           for i := 0 to (p - 1) do
  582.             for i2 := 0 to (x - 1) do
  583.             begin
  584.               SetLength(Result[i], x);
  585.               if (a < h) then
  586.               begin
  587.                 Result[i][i2] := Integer(TIA[a]);
  588.                 Inc(a);
  589.               end else
  590.               begin
  591.                 SetLength(Result[i], i2);
  592.                 Exit;
  593.               end;
  594.             end;
  595.         end else
  596.           f := True;      
  597.         pm_PartAmount:
  598.         case (h <= 0) of
  599.           False:
  600.           begin
  601.             if (h < (x - 1)) then
  602.               x := (h + 1);
  603.             p := Floor((h + 1) / x);
  604.             if (p = 0) then
  605.               p := 1;
  606.             e := ((h + 1) - (p * x));
  607.             if (e >= (h + 1)) then
  608.               e := 0;
  609.             SetLength(Result, x);
  610.             for i := 0 to (x - 1) do
  611.             begin
  612.               if ((e >= (i + 1)) and (e > 0)) then
  613.                 SetLength(Result[i], (p + 1))
  614.               else
  615.                 if (i <= h) then
  616.                   SetLength(Result[i], p);
  617.               h2 := High(Result[i]);
  618.               for i2 := 0 to h2 do
  619.               begin
  620.                 Result[i][i2] := Integer(TIA[a]);
  621.                 Inc(a);
  622.               end;
  623.             end;      
  624.           end;
  625.           True: f := True;
  626.         end;
  627.       end;
  628.       if f then
  629.       begin                    
  630.         SetLength(Result, 1);
  631.         l := Length(TIA);
  632.         SetLength(Result[0], l);
  633.         for z := 0 to (l - 1) do
  634.           Result[0][z] := Integer(TIA[z]);
  635.       end;
  636.     end;      
  637.     False: SetLength(Result, 0);          
  638.   end;
  639. end;
  640.  
  641. {==============================================================================]
  642.   Explanation: Returns a TIA from start position, where step is the difference between each range value.
  643.                Count is the size of the result..
  644.   Examples: (3, -1, 3) => [3, 2, 1] and (0, 2, 4) => [0, 2, 4, 6]
  645. [==============================================================================}
  646. function MSSL_TIARangeFrom(start, step, count: Integer): TIntArray; stdcall;
  647. var
  648.   i: Integer;
  649. begin
  650.   case (count > 0) of
  651.     True:
  652.     begin
  653.       SetLength(Result, count);
  654.       for i := 0 to (count - 1) do
  655.         Result[i] := (start + (i * step));
  656.     end;
  657.     False: SetLength(Result, 0);
  658.   end;
  659. end;
  660.  
  661. {==============================================================================]
  662.   Explanation: Returns array of items from TIA by IDs.
  663.                Stores invalid ID's [index positions] to iIDs.
  664. [==============================================================================}
  665. function MSSL_TIAGetEx(TIA, IDs: TIntArray; var iIDs: TIntArray): TIntArray; stdcall;
  666. var
  667.   i, h, h2, iC, rC: Integer;
  668. begin
  669.   SetLength(Result, 0);
  670.   h := High(TIA);
  671.   h2 := High(IDs);
  672.   case ((h2 > -1) and (h > -1)) of
  673.     True:
  674.     begin
  675.       SetLength(Result, (h2 + 1));
  676.       SetLength(iIDs, (h2 + 1));
  677.       for i := 0 to h2 do
  678.       case ((IDs[i] <= h) and (IDs[i] > -1)) of
  679.         True:
  680.         begin
  681.           Result[rC] := Integer(TIA[IDs[i]]);
  682.           Inc(rC);
  683.         end;
  684.         False:
  685.         begin
  686.           iIDs[iC] := i;
  687.           Inc(iC);
  688.         end;
  689.       end;
  690.       SetLength(iIDs, iC);
  691.     end;
  692.     False:
  693.     begin
  694.       SetLength(iIDs, (h2 + 1));
  695.       for i := 0 to h2 do
  696.         iIDs[i] := Integer(IDs[i]);
  697.     end;
  698.   end;  
  699.   SetLength(Result, rC);
  700. end;
  701.  
  702. {==============================================================================]
  703.   Explanation: Returns item[s] from TIA by IDs. Ignores invalid ID's.
  704. [==============================================================================}
  705. function MSSL_TIAGet(TIA, IDs: TIntArray): TIntArray; stdcall;
  706. var
  707.   i, h, h2, r: Integer;
  708. begin
  709.   h := High(TIA);
  710.   h2 := High(IDs);
  711.   if ((h2 > -1) and (h > -1)) then
  712.   begin
  713.     SetLength(Result, (h2 + 1));
  714.     for i := 0 to h2 do
  715.       if ((IDs[i] <= h) and (IDs[i] > -1)) then
  716.       begin
  717.         Result[r] := Integer(TIA[IDs[i]]);
  718.         Inc(r);
  719.       end;
  720.   end;
  721.   SetLength(Result, r);
  722. end;
  723.  
  724. {==============================================================================]
  725.   Explanation: Removes integers by x from TIA.
  726. [==============================================================================}
  727. procedure MSSL_TIARemoveEx(var TIA: TIntArray; x: TIntArray); stdcall;
  728. var
  729.   i: Integer;
  730. begin
  731.   for i := High(x) downto 0 do
  732.   begin        
  733.     TIARemoveEx(TIA, x[i], True);
  734.     if (High(TIA) < 0) then
  735.       Break;
  736.     TIARemoveEx(x, x[i], True);
  737.   end;
  738. end;
  739.  
  740. {==============================================================================]
  741.   Explanation: Copies source to target. If resetTarget is set to true,
  742.                target will be cleared before the copying process.
  743. [==============================================================================}
  744. procedure MSSL_TIACopy(source: TIntArray; var target: TIntArray; resetTarget: Boolean); stdcall;
  745. var
  746.   i, tAL, sAL: Integer;
  747. begin
  748.   if resetTarget then
  749.     SetLength(target, 0);
  750.   tAL := Length(target);
  751.   sAL := Length(source);
  752.   SetLength(target, (tAL + sAL));
  753.   for i := 0 to (sAL - 1) do
  754.     target[(tAL + i)] := Integer(source[i]);
  755. end;
  756.  
  757. {==============================================================================]
  758.   Explanation: Moves source to target. If resetTarget is set to true,
  759.                target will be cleared before the moving process.
  760. [==============================================================================}
  761. procedure MSSL_TIATransferEx(var source, target: TIntArray; resetTarget: Boolean); stdcall;
  762. begin
  763.   MSSL_TIACopy(source, target, resetTarget);
  764.   SetLength(source, 0);
  765. end;
  766.  
  767. {==============================================================================]
  768.   Explanation: Moves source to target.
  769.   NOTE: Target wont get cleaned before moving source!
  770. [==============================================================================}
  771. procedure MSSL_TIATransfer(var source, target: TIntArray); stdcall;
  772. begin
  773.   MSSL_TIACopy(source, target, False);
  774.   SetLength(source, 0);  
  775. end;
  776.  
  777. {==============================================================================]
  778.   Explanation: Plants/places ints to index position in TIA.
  779.                Like TIAInsert(), with an exception that this inserts array of integers.
  780.                Returns the highest index from TIA in the end.
  781. [==============================================================================}
  782. function MSSL_TIAPlant(var TIA: TIntArray; index: Integer; ints: TIntArray): Integer; stdcall;
  783. var
  784.   i, l, h: Integer;
  785. begin
  786.   h := High(ints);
  787.   if (h > -1) then
  788.   begin                                      
  789.     l := Length(TIA);
  790.     SetLength(TIA, (l + (h + 1)));
  791.     if (index < 0) then
  792.       index := 0;
  793.     if (index > l) then
  794.       index := l;      
  795.     for i := (l + (h + 1) - 1) downto (index + (h + 1)) do
  796.       TIA[i] := TIA[(i - (h + 1))];    
  797.     for i := 0 to h do
  798.       TIA[(i + index)] := Integer(ints[i]);      
  799.   end;
  800.   Result := High(TIA);
  801. end;
  802.  
  803. {==============================================================================]
  804.   Explanation: Returns integer (by pick_ID) from TIA and then deletes it from TIA.
  805.                Result will be -1, if TIA is empty of pick_ID invalid.
  806. [==============================================================================}
  807. function MSSL_TIAPick(var TIA: TIntArray; pick_ID: Integer): Integer; stdcall;
  808. var
  809.   h, i: Integer;
  810. begin
  811.   h := High(TIA);
  812.   if ((h > -1) and InRange(pick_ID, 0, h)) then
  813.   begin
  814.     Result := Integer(TIA[pick_ID]);
  815.     for i := pick_ID to (h - 1) do
  816.       TIA[i] := TIA[(i + 1)];
  817.     SetLength(TIA, h);
  818.   end else
  819.     Result := -1;
  820. end;
  821.  
  822. {==============================================================================]
  823.   Explanation: Returns integers (by pick_IDs) from TIA and then deletes em. Ignores invalid indexes. DYNAMIC!
  824. [==============================================================================}
  825. function MSSL_TIAPickEx(var TIA: TIntArray; pick_IDs: TIntArray): TIntArray; stdcall;
  826. var
  827.   h, h2, i, d, r: Integer;
  828. begin
  829.   h2 := High(TIA);
  830.   h := High(pick_IDs);
  831.   if ((h2 > -1) and (h > -1)) then
  832.   begin        
  833.     SetLength(Result, (h2 + 1));
  834.     for i := 0 to h do
  835.       if ((pick_IDs[i] <= h2) and (pick_IDs[i] > -1)) then
  836.       begin
  837.         Result[r] := Integer(TIA[pick_IDs[i]]);
  838.         Inc(r);
  839.         for d := pick_IDs[i] to (h2 - 1) do
  840.           TIA[d] := TIA[(d + 1)];
  841.         Dec(h2);
  842.         if (h2 < 0) then
  843.           Break;
  844.       end;
  845.     SetLength(TIA, h2);
  846.     SetLength(Result, r);
  847.   end else
  848.     SetLength(Result, 0);
  849. end;
  850.  
  851. {==============================================================================]
  852.   Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
  853.                If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.
  854. [==============================================================================}
  855. function MSSL_TIAMatchEx(TIA1, TIA2, specialMatches: TIntArray): Integer; stdcall;
  856. var
  857.   i, m: Integer;
  858. begin
  859.   Result := 0;
  860.   m := Min(High(TIA1), High(TIA2));
  861.   for i := 0 to m do
  862.   case (TIA1[i] = TIA2[i]) of
  863.     True: Inc(Result);
  864.     False:
  865.     if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
  866.       Inc(Result);
  867.   end;        
  868. end;
  869.  
  870. {==============================================================================]
  871.   Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
  872.                If either TIA1[*] or TIA2[*] contains specialMatch value, it will be counted as match.
  873. [==============================================================================}
  874. function MSSL_TIAMatch2(TIA1, TIA2: TIntArray; specialMatch: Integer): Integer; stdcall;
  875. var
  876.   i, m: Integer;
  877. begin
  878.   Result := 0;
  879.   m := Min(High(TIA1), High(TIA2));
  880.   for i := 0 to m do
  881.   case (TIA1[i] = TIA2[i]) of
  882.     True: Inc(Result);
  883.     False:
  884.     if ((TIA1[i] = specialMatch) or (TIA2[i] = specialMatch)) then
  885.       Inc(Result);
  886.   end;        
  887. end;
  888.  
  889. {==============================================================================]
  890.   Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
  891. [==============================================================================}
  892. function MSSL_TIAMatch(TIA1, TIA2: TIntArray): Integer; stdcall;
  893. var
  894.   i, m: Integer;
  895. begin
  896.   Result := 0;
  897.   m := Min(High(TIA1), High(TIA2));
  898.   for i := 0 to m do
  899.     if (TIA1[i] = TIA2[i]) then
  900.       Inc(Result);
  901. end;
  902.  
  903. {==============================================================================]
  904.   Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
  905.                If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.
  906. [==============================================================================}
  907. function MSSL_TIAMatchesEx(TIA1, TIA2, specialMatches: TIntArray): TIntArray; stdcall;
  908. var
  909.   i, m, r: Integer;
  910. begin
  911.   m := Min(High(TIA1), High(TIA2));
  912.   if (m > -1) then                
  913.   begin
  914.     SetLength(Result, (m + 1));
  915.     for i := 0 to m do
  916.     case (TIA1[i] = TIA2[i]) of
  917.       True:
  918.       begin
  919.         Result[r] := i;
  920.         Inc(r);    
  921.       end;
  922.       False:
  923.       if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
  924.       begin
  925.         Result[r] := i;
  926.         Inc(r);    
  927.       end;
  928.     end;
  929.     SetLength(Result, r);
  930.   end else
  931.     SetLength(Result, 0);        
  932. end;
  933.  
  934. {==============================================================================]
  935.   Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
  936.                If either TIA1[*] or TIA2[*] contains specialMatch value, it will be counted as match.
  937. [==============================================================================}
  938. function MSSL_TIAMatches2(TIA1, TIA2: TIntArray; specialMatch: Integer): TIntArray; stdcall;
  939. var
  940.   i, m, r: Integer;
  941. begin
  942.   m := Min(High(TIA1), High(TIA2));
  943.   if (m > -1) then
  944.   begin  
  945.     SetLength(Result, (m + 1));
  946.     for i := 0 to m do
  947.     case (TIA1[i] = TIA2[i]) of
  948.       True:  
  949.       begin
  950.         Result[r] := i;
  951.         Inc(r);
  952.       end;
  953.       False:
  954.       if ((TIA1[i] = specialMatch) or (TIA2[i] = specialMatch)) then
  955.       begin
  956.         Result[r] := i;
  957.         Inc(r);    
  958.       end;
  959.     end;
  960.     SetLength(Result, r);  
  961.   end else
  962.     SetLength(Result, 0);      
  963. end;
  964.  
  965. {==============================================================================]
  966.   Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
  967. [==============================================================================}
  968. function MSSL_TIAMatches(TIA1, TIA2: TIntArray): TIntArray; stdcall;
  969. var
  970.   i, m, r: Integer;
  971. begin
  972.   m := Min(High(TIA1), High(TIA2));
  973.   if (m > -1) then
  974.   begin  
  975.     SetLength(Result, (m + 1));
  976.     for i := 0 to m do
  977.       if (TIA1[i] = TIA2[i]) then
  978.       begin
  979.         Result[r] := i;
  980.         Inc(r);
  981.       end;
  982.     SetLength(Result, r);  
  983.   end else
  984.     SetLength(Result, 0);        
  985. end;
  986.  
  987. {==============================================================================]
  988.   Explanation: Returns the count of positions where TIA1[*] does not match TIA2[*].
  989.                (* = same positions)
  990. [==============================================================================}
  991. function MSSL_TIAUnmatch(TIA1, TIA2: TIntArray): Integer; stdcall;
  992. var
  993.   i, m: Integer;
  994. begin
  995.   Result := 0;
  996.   m := Min(High(TIA1), High(TIA2));
  997.   for i := 0 to m do
  998.     if (TIA1[i] <> TIA2[i]) then
  999.       Inc(Result);
  1000. end;
  1001.  
  1002. {==============================================================================]
  1003.   Explanation: Returns all positions where TIA1[*] does not match TIA2[*].
  1004.                (* = same positions)
  1005. [==============================================================================}
  1006. function MSSL_TIAUnmatches(TIA1, TIA2: TIntArray): TIntArray; stdcall;
  1007. var
  1008.   i, m, r: Integer;
  1009. begin
  1010.   m := Min(High(TIA1), High(TIA2));
  1011.   if (m > -1) then
  1012.   begin
  1013.     SetLength(Result, (m + 1));
  1014.     for i := 0 to m do
  1015.       if (TIA1[i] <> TIA2[i]) then
  1016.       begin
  1017.         Result[r] := i;
  1018.         Inc(r);
  1019.       end;    
  1020.   end;
  1021.   SetLength(Result, r);
  1022. end;
  1023.  
  1024. {==============================================================================]
  1025.   Explanation: Will return all the items that are unique in TIA.
  1026. [==============================================================================}
  1027. function MSSL_TIAGetUniques(TIA: TIntArray): TIntArray; stdcall;
  1028. var
  1029.   h, i, i2, r: Integer;
  1030. begin
  1031.   h := High(TIA);
  1032.   if (h < 1) then
  1033.   begin
  1034.     SetLength(Result, (h + 1));
  1035.     for i := 0 to h do
  1036.       Result[i] := Integer(TIA[i]);
  1037.     Exit;
  1038.   end;
  1039.   SetLength(Result, (h + 1));
  1040.   for i := 0 to h do
  1041.   begin
  1042.     for i2 := 0 to h do
  1043.       if (i2 <> i) then
  1044.         if (TIA[i] = TIA[i2]) then
  1045.           Break;
  1046.     if (i2 <= h) then
  1047.       Continue;
  1048.     Result[r] := Integer(TIA[i]);
  1049.     Inc(r);
  1050.   end;
  1051.   SetLength(Result, r);
  1052. end;
  1053.  
  1054. {==============================================================================]
  1055.   Explanation: Returns true if TIA is equal to TIA2.
  1056.                Ignores specialMatch value in both of the arrays
  1057.                (..that means, they are always counted as match!)
  1058. [==============================================================================}
  1059. function MSSL_TIAEquals(TIA1, TIA2: TIntArray; specialMatch: Integer): Boolean; stdcall;
  1060. var
  1061.   h, i: Integer;
  1062. begin
  1063.   Result := False;
  1064.   h := High(TIA1);
  1065.   if ((h > -1) and (h = High(TIA2))) then
  1066.   begin
  1067.     for i := 0 to h do
  1068.       if ((TIA1[i] <> specialMatch) and (TIA2[i] <> specialMatch) and (TIA1[i] <> TIA2[i])) then
  1069.         Break;  
  1070.     Result := (i > h);
  1071.   end;
  1072. end;
  1073.  
  1074. {==============================================================================]
  1075.   Explanation: Returns true if TIA is equal to TIA2.
  1076.                Ignores values from specialMatches in both of the arrays
  1077.                (..that means, they are always counted as match!)
  1078. [==============================================================================}
  1079. function MSSL_TIAEqualsEx(TIA1, TIA2, specialMatches: TIntArray): Boolean; stdcall;
  1080. var
  1081.   h, i: Integer;
  1082. begin
  1083.   h := High(TIA1);
  1084.   if ((h > -1) and (h = High(TIA2))) then
  1085.   begin
  1086.     for i := 0 to h do
  1087.       if (not TIAContains(specialMatches, TIA1[i]) and not TIAContains(specialMatches, TIA2[i]) and (TIA1[i] <> TIA2[i])) then
  1088.         Break;  
  1089.     Result := (i > h);
  1090.   end else
  1091.     Result := False;
  1092. end;
  1093.  
  1094. {==============================================================================]
  1095.   Explanation: Returns true if ALL values in arr are identical to each other.
  1096. [==============================================================================}
  1097. function MSSL_TIAAllValuesSame(arr: TIntArray): Boolean; stdcall;
  1098. var
  1099.   h, i: Integer;
  1100. begin
  1101.   h := High(arr);
  1102.   if (h < 1) then
  1103.   begin
  1104.     Result := (h = 0);
  1105.     Exit;
  1106.   end;  
  1107.   Result := False;
  1108.   for i := 1 to h do
  1109.     if (arr[i] <> arr[0]) then
  1110.       Exit;
  1111.   Result := True;
  1112. end;
  1113.  
  1114. {==============================================================================]
  1115.   Explanation: Returns true if ALL values in arr are unique to each other.
  1116. [==============================================================================}
  1117. function MSSL_TIAAllValuesUnique(arr: TIntArray): Boolean; stdcall;
  1118. var
  1119.   h, i, i2: Integer;
  1120. begin
  1121.   h := High(arr);
  1122.   if (h < 1) then
  1123.   begin
  1124.     Result := (h = 0);
  1125.     Exit;
  1126.   end;    
  1127.   Result := False;
  1128.   for i := 0 to (h - 1) do
  1129.     for i2 := (i + 1) to h do
  1130.       if (i <> i2) then
  1131.       begin
  1132.         Result := (arr[i] <> arr[i2]);
  1133.         if not Result then
  1134.           Exit;
  1135.       end;
  1136. end;
  1137.  
  1138. {==============================================================================]
  1139.   Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
  1140.                that are within a given difference range (minDifference, maxDifference) from each other.
  1141. [==============================================================================}
  1142. function MSSL_TIASplitEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray; stdcall;
  1143. var
  1144.   a, b, h, l, i, r, d, t: Integer;
  1145. begin
  1146.   h := High(TIA);
  1147.   if (h > -1) then
  1148.   begin                
  1149.     SetLength(Result, (h + 1));
  1150.     SetLength(Result[0], 1);
  1151.     Result[0][0] := Integer(TIA[0]);
  1152.     if (h > 0) then
  1153.     begin                  
  1154.       r := 1;
  1155.       if (minDifference > maxDifference) then
  1156.       begin
  1157.         t := minDifference;
  1158.         minDifference := maxDifference;
  1159.         maxDifference := t;
  1160.       end;
  1161.       for i := 1 to h do    
  1162.       begin
  1163.         for a := 0 to (r - 1) do
  1164.         begin
  1165.           l := Length(Result[a]);
  1166.           for b := 0 to (l - 1) do      
  1167.           begin
  1168.             d := Abs(TIA[i] - Result[a][b]);
  1169.             if ((d >= minDifference) and (d <= maxDifference)) then
  1170.             begin
  1171.               SetLength(Result[a], (l + 1));
  1172.               Result[a][l] := Integer(TIA[i]);
  1173.               Break;
  1174.             end;
  1175.           end;  
  1176.           if (b < l) then
  1177.             Break;
  1178.         end;    
  1179.         if (a >= r) then
  1180.         begin
  1181.           SetLength(Result[r], 1);
  1182.           Result[r][0] := Integer(TIA[i]);
  1183.           Inc(r);
  1184.         end;
  1185.       end;
  1186.     end;
  1187.   end;
  1188.   SetLength(Result, r);
  1189. end;
  1190.  
  1191. {==============================================================================]
  1192.   Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
  1193.                that are within a given difference from each other.
  1194. [==============================================================================}
  1195. function MSSL_TIASplit(TIA: TIntArray; difference: Integer): T2DIntArray; stdcall;
  1196. begin
  1197.   Result := MSSL_TIASplitEx(TIA, 0, difference);
  1198. end;
  1199.  
  1200. {==============================================================================]
  1201.   Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
  1202.                that are within a given difference range (minDifference, maxDifference) of the first integer value in the sub-array.
  1203. [==============================================================================}
  1204. function MSSL_TIAGroupEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray; stdcall;
  1205. var
  1206.   a, h, l, i, r, d, t: Integer;
  1207. begin
  1208.   h := High(TIA);
  1209.   if (h > -1) then
  1210.   begin                
  1211.     SetLength(Result, (h + 1));
  1212.     SetLength(Result[0], 1);
  1213.     Result[0][0] := Integer(TIA[0]);
  1214.     if (h > 0) then
  1215.     begin
  1216.       r := 1;
  1217.       if (minDifference > maxDifference) then
  1218.       begin
  1219.         t := minDifference;
  1220.         minDifference := maxDifference;
  1221.         maxDifference := t;
  1222.       end;
  1223.       for i := 1 to h do    
  1224.       begin
  1225.         for a := 0 to (r - 1) do
  1226.         begin
  1227.           d := Abs(TIA[i] - Result[a][0]);
  1228.           if ((d >= minDifference) and (d <= maxDifference)) then
  1229.           begin
  1230.             l := Length(Result[a]);
  1231.             SetLength(Result[a], (l + 1));
  1232.             Result[a][l] := Integer(TIA[i]);
  1233.             Break;
  1234.           end;
  1235.         end;    
  1236.         if (a >= r) then
  1237.         begin
  1238.           SetLength(Result[r], 1);
  1239.           Result[r][0] := Integer(TIA[i]);
  1240.           Inc(r);
  1241.         end;
  1242.       end;
  1243.     end;
  1244.   end;
  1245.   SetLength(Result, r);
  1246. end;
  1247.  
  1248. {==============================================================================]
  1249.   Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
  1250.                that are within a given difference range of the first integer value in the sub-array.
  1251. [==============================================================================}
  1252. function MSSL_TIAGroup(TIA: TIntArray; difference: Integer): T2DIntArray; stdcall;
  1253. begin
  1254.   Result := MSSL_TIAGroupEx(TIA, 0, difference);
  1255. end;
  1256.  
  1257. type
  1258.   TCommand = record
  1259.     procAddr: Pointer;
  1260.     procDef: string;
  1261.   end;
  1262.  
  1263. var
  1264.   commands: array of TCommand;
  1265.   commandsLoaded: Boolean;
  1266.  
  1267. procedure AddCommand(procAddr: Pointer; procDef: string);
  1268. var
  1269.   l: Integer;
  1270. begin
  1271.   l := Length(commands);
  1272.   SetLength(commands, (l + 1));
  1273.   commands[l].procAddr := procAddr;
  1274.   commands[l].procDef := procDef;
  1275. end;
  1276.  
  1277. procedure SetupCommands;
  1278. begin
  1279.   AddCommand(@MSSL_TIAByRange, 'function MSSL_TIAByRange(aStart, aFinish: Integer): TIntArray;');
  1280.   AddCommand(@MSSL_TIAByRange2Bit, 'function MSSL_TIAByRange2Bit(aStart, aFinish: Integer): TIntArray;');
  1281.   AddCommand(@MSSL_TIAOfInteger, 'function MSSL_TIAOfInteger(x, count: Integer): TIntArray;');
  1282.   AddCommand(@MSSL_IntDigits, 'function MSSL_IntDigits(int: Integer): TIntArray;');
  1283.   AddCommand(@MSSL_StrIsInt, 'function MSSL_StrIsInt(str: string): Boolean;');
  1284.   AddCommand(@MSSL_IntSetMin, 'procedure MSSL_IntSetMin(var val: Integer; x: Integer);');
  1285.   AddCommand(@MSSL_IntSetMax, 'procedure MSSL_IntSetMax(var val: Integer; x: Integer);');
  1286.   AddCommand(@MSSL_IntSetRange, 'procedure MSSL_IntSetRange(var val: Integer; mn, mx: Integer);');
  1287.   AddCommand(@MSSL_TIASetMin, 'procedure MSSL_TIASetMin(var TIA: TIntArray; x: Integer);');
  1288.   AddCommand(@MSSL_TIASetMax, 'procedure MSSL_TIASetMax(var TIA: TIntArray; x: Integer);');
  1289.   AddCommand(@MSSL_TIASetRange, 'procedure MSSL_TIASetRange(var TIA: TIntArray; mn, mx: Integer);');
  1290.   AddCommand(@MSSL_TIAControlByRange, 'procedure MSSL_TIAControlByRange(var TIA: TIntArray; minimum, maximum: Integer; method: MSSL_TControlMethod);');
  1291.   AddCommand(@MSSL_TIABuiltWith, 'function MSSL_TIABuiltWith(TIA, allowed: TIntArray): Boolean;');
  1292.   AddCommand(@MSSL_TIARandomizeEx, 'procedure MSSL_TIARandomizeEx(var TIA: TIntArray; shuffles: Integer);');
  1293.   AddCommand(@MSSL_TIARandomize, 'procedure MSSL_TIARandomize(var TIA: TIntArray);');
  1294.   AddCommand(@MSSL_TIADelete, 'function MSSL_TIADelete(var TIA: TIntArray; x: Integer): Boolean;');
  1295.   AddCommand(@MSSL_TIARemove, 'procedure MSSL_TIARemove(var TIA: TIntArray; x: TIntArray);');
  1296.   AddCommand(@MSSL_TIAAdd, 'function MSSL_TIAAdd(var TIA: TIntArray; addTIA: TIntArray): Integer;');
  1297.   AddCommand(@MSSL_TIAPositions, 'function MSSL_TIAPositions(TIA: TIntArray; x: Integer): TIntArray;');
  1298.   AddCommand(@MSSL_TIAPositionsMulti, 'function MSSL_TIAPositionsMulti(TIA, ints: TIntArray): TIntArray;');
  1299.   AddCommand(@MSSL_TIAPositionsEx, 'function MSSL_TIAPositionsEx(TIA, ints: TIntArray): TIntArray;');
  1300.   AddCommand(@MSSL_TIACopyEx, 'function MSSL_TIACopyEx(TIA: TIntArray; pos1, pos2: Integer): TIntArray;');
  1301.   AddCommand(@MSSL_TIAMove, 'function MSSL_TIAMove(var TIA: TIntArray; oldIndex, newIndex: Integer): Boolean;');
  1302.   AddCommand(@MSSL_TIAToParts, 'function MSSL_TIAToParts(TIA: TIntArray; method: MSSL_TPartitionMethod; x: Integer): T2DIntArray;');
  1303.   AddCommand(@MSSL_TIARangeFrom, 'function MSSL_TIARangeFrom(start, step, count: Integer): TIntArray;');
  1304.   AddCommand(@MSSL_TIAGetEx, 'function MSSL_TIAGetEx(TIA, IDs: TIntArray; var iIDs: TIntArray): TIntArray;');
  1305.   AddCommand(@MSSL_TIAGet, 'function MSSL_TIAGet(TIA, IDs: TIntArray): TIntArray;');
  1306.   AddCommand(@MSSL_TIARemoveEx, 'procedure MSSL_TIARemoveEx(var TIA: TIntArray; x: TIntArray);');
  1307.   AddCommand(@MSSL_TIACopy, 'procedure MSSL_TIACopy(source: TIntArray; var target: TIntArray; resetTarget: Boolean);');
  1308.   AddCommand(@MSSL_TIATransferEx, 'procedure MSSL_TIATransferEx(var source, target: TIntArray; resetTarget: Boolean);');
  1309.   AddCommand(@MSSL_TIATransfer, 'procedure MSSL_TIATransfer(var source, target: TIntArray);');
  1310.   AddCommand(@MSSL_TIAPlant, 'function MSSL_TIAPlant(var TIA: TIntArray; index: Integer; ints: TIntArray): Integer;');
  1311.   AddCommand(@MSSL_TIAPick, 'function MSSL_TIAPick(var TIA: TIntArray; pick_ID: Integer): Integer;');
  1312.   AddCommand(@MSSL_TIAPickEx, 'function MSSL_TIAPickEx(var TIA: TIntArray; pick_IDs: TIntArray): TIntArray;');
  1313.   AddCommand(@MSSL_TIAMatchEx, 'function MSSL_TIAMatchEx(TIA1, TIA2, specialMatches: TIntArray): Integer;');
  1314.   AddCommand(@MSSL_TIAMatch2, 'function MSSL_TIAMatch2(TIA1, TIA2: TIntArray; specialMatch: Integer): Integer;');
  1315.   AddCommand(@MSSL_TIAMatch, 'function MSSL_TIAMatch(TIA1, TIA2: TIntArray): Integer;');
  1316.   AddCommand(@MSSL_TIAMatchesEx, 'function MSSL_TIAMatchesEx(TIA1, TIA2, specialMatches: TIntArray): TIntArray;');
  1317.   AddCommand(@MSSL_TIAMatches2, 'function MSSL_TIAMatches2(TIA1, TIA2: TIntArray; specialMatch: Integer): TIntArray;');
  1318.   AddCommand(@MSSL_TIAMatches, 'function MSSL_TIAMatches(TIA1, TIA2: TIntArray): TIntArray;');
  1319.   AddCommand(@MSSL_TIAUnmatch, 'function MSSL_TIAUnmatch(TIA1, TIA2: TIntArray): Integer;');
  1320.   AddCommand(@MSSL_TIAUnmatches, 'function MSSL_TIAUnmatches(TIA1, TIA2: TIntArray): TIntArray;');
  1321.   AddCommand(@MSSL_TIAGetUniques, 'function MSSL_TIAGetUniques(TIA: TIntArray): TIntArray;');
  1322.   AddCommand(@MSSL_TIAEquals, 'function MSSL_TIAEquals(TIA1, TIA2: TIntArray; specialMatch: Integer): Boolean;');
  1323.   AddCommand(@MSSL_TIAEqualsEx, 'function MSSL_TIAEqualsEx(TIA1, TIA2, specialMatches: TIntArray): Boolean;');
  1324.   AddCommand(@MSSL_TIAAllValuesSame, 'function MSSL_TIAAllValuesSame(arr: TIntArray): Boolean;');
  1325.   AddCommand(@MSSL_TIAAllValuesUnique, 'function MSSL_TIAAllValuesUnique(arr: TIntArray): Boolean;');
  1326.   AddCommand(@MSSL_TIASplitEx, 'function MSSL_TIASplitEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray;');
  1327.   AddCommand(@MSSL_TIASplit, 'function MSSL_TIASplit(TIA: TIntArray; difference: Integer): T2DIntArray;');
  1328.   AddCommand(@MSSL_TIAGroupEx, 'function MSSL_TIAGroupEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray;');
  1329.   AddCommand(@MSSL_TIAGroup, 'function MSSL_TIAGroup(TIA: TIntArray; difference: Integer): T2DIntArray;');
  1330.   commandsLoaded := True;
  1331. end;
  1332.  
  1333. procedure UnsetupCommands;
  1334. begin
  1335.   SetLength(commands, 0);
  1336.   commandsLoaded := False;
  1337. end;
  1338.  
  1339. function GetFunctionCount(): Integer; stdcall;
  1340. begin
  1341.   if not commandsLoaded then
  1342.     SetupCommands;
  1343.   Result := Length(commands);
  1344. end;
  1345.  
  1346. function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PAnsiChar): Integer; stdcall;
  1347. var
  1348.   command: TCommand;
  1349. begin
  1350.   case ((x > -1) and InRange(x, Low(commands), High(commands))) of
  1351.     True:
  1352.     begin
  1353.       ProcAddr := commands[x].procAddr;
  1354.       StrPCopy(ProcDef, commands[x].procDef);
  1355.       Result := x;
  1356.       if (Result = High(commands)) then
  1357.         UnsetupCommands;
  1358.     end;
  1359.     False: Result := -1;
  1360.   end;
  1361. end;
  1362.  
  1363. exports GetFunctionCount;
  1364. exports GetFunctionInfo;
  1365.  
  1366. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement