Janilabo

Janilabo | TSACopyEx() [SCAR Divi]

Apr 27th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.66 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Copies TSA from pos1 to pos2.                  
  3. [==============================================================================}
  4. function TSACopyEx(TSA: TStrArray; pos1, pos2: Integer): TStrArray;
  5. var
  6.   i, l: Integer;
  7. begin
  8.   l := Length(TSA);
  9.   if (l > 0) then
  10.   begin      
  11.     if (pos1 < 0) then
  12.       pos1 := 0;
  13.     if (pos1 > (l - 1)) then
  14.       pos1 := (l - 1);
  15.     if (pos2 < 0) then
  16.       pos2 := 0;
  17.     if (pos2 > (l - 1)) then
  18.       pos2 := (l - 1);    
  19.     case (pos1 <> pos2) of
  20.       True:
  21.       begin
  22.         SetLength(Result, (IAbs(pos1 - pos2) + 1));
  23.         case (pos1 < pos2) of
  24.           True:
  25.           for i := pos1 to pos2 do
  26.             Result[(i - pos1)] := string(TSA[i]);
  27.           False:
  28.           for i := pos1 downto pos2 do
  29.             Result[(pos1 - i)] := string(TSA[i]);
  30.         end;
  31.       end;
  32.       False: Result := [string(TSA[pos1])];  
  33.     end;
  34.   end else
  35.     SetLength(Result, 0);
  36. end;
  37.  
  38. var
  39.   s: string;
  40.   h, i: Integer;
  41.   a, b: TStrArray;
  42.  
  43. const
  44.   START = 1;
  45.   FINISH = 8;
  46.  
  47. begin
  48.   ClearDebug;
  49.   a := ['Test0', 'Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9'];
  50.   b := TSACopyEx(a, START, FINISH);
  51.   h := High(b);
  52.   for i := 0 to h do
  53.     s := (s + '"' +  b[i] + '" ');
  54.   WriteLn('TSACopyEx(a, ' + IntToStr(START) + ', ' + IntToStr(FINISH) + '): ' + s);
  55.   s := '';
  56.   b := TSACopyEx(a, FINISH, START);
  57.   h := High(b);
  58.   for i := 0 to h do
  59.     s := (s + '"' +  b[i] + '" ');
  60.   WriteLn('TSACopyEx(a, ' + IntToStr(FINISH) + ', ' + IntToStr(START) + '): ' + s);
  61. end.
Advertisement
Add Comment
Please, Sign In to add comment