Janilabo

Janilabo | TSAGet() [SCAR Divi]

Apr 27th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.94 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Returns array of items from TSA by IDs. Ignores invalid ID's.                    
  3. [==============================================================================}
  4. function TSAGet(TSA: TStrArray; IDs: TIntArray): TStrArray;
  5. var
  6.   i, h, h2, r: Integer;
  7. begin
  8.   h := High(TSA);
  9.   h2 := High(IDs);    
  10.   if ((h2 > -1) and (h > -1)) then
  11.   begin
  12.     SetLength(Result, (h2 + 1));
  13.     for i := 0 to h2 do
  14.       if ((IDs[i] <= h) and (IDs[i] > -1)) then
  15.       begin
  16.         Result[r] := string(TSA[IDs[i]]);
  17.         Inc(r);
  18.       end;        
  19.   end;
  20.   SetLength(Result, r);
  21. end;
  22.  
  23. var
  24.   tmp: TStrArray;
  25.   h, i: Integer;
  26.  
  27. begin
  28.   ClearDebug;
  29.   tmp := TSAGet(['Test0', 'Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9'], [-1, 1, 2, 3, 4, 999]);
  30.   h := High(tmp);
  31.   for i := 0 to h do
  32.     WriteLn(tmp[i]);
  33. end.
Advertisement
Add Comment
Please, Sign In to add comment