Janilabo

Janilabo | TSAPlant() [SCAR Divi]

Apr 27th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.16 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Plants/places strs to index position in TSA.
  3.                Like TSAInsert(), with an exception that this inserts array of strings.
  4.                Returns the highest index from TSA in the end.                  
  5. [==============================================================================}
  6. function TSAPlant(var TSA: TStrArray; index: Integer; strs: TStrArray): Integer;
  7. var
  8.   i, l, h: Integer;
  9. begin
  10.   h := High(strs);
  11.   if (h > -1) then
  12.   begin                                      
  13.     l := Length(TSA);
  14.     SetLength(TSA, (l + (h + 1)));
  15.     if (index < 0) then
  16.       index := 0;
  17.     if (index > l) then
  18.       index := l;      
  19.     for i := (l + (h + 1) - 1) downto (index + (h + 1)) do
  20.       Swap(TSA[i], TSA[(i - (h + 1))]);    
  21.     for i := 0 to h do
  22.       TSA[(i + index)] := string(strs[i]);      
  23.   end;          
  24.   Result := High(TSA);
  25. end;
  26.  
  27. var
  28.   tmp: TStrArray;
  29.   h, i: Integer;
  30.  
  31. begin
  32.   ClearDebug;
  33.   tmp := ['a', 'b', 'f', 'g'];
  34.   TSAPlant(tmp, 2, ['c', 'd', 'e']);
  35.   h := High(tmp);
  36.   for i := 0 to h do
  37.     WriteLn(tmp[i]);
  38. end.
Advertisement
Add Comment
Please, Sign In to add comment