Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Copies TSA from pos1 to pos2.
- [==============================================================================}
- function TSACopyEx(TSA: TStrArray; pos1, pos2: Integer): TStrArray;
- var
- i, l: Integer;
- begin
- l := Length(TSA);
- if (l > 0) then
- begin
- if (pos1 < 0) then
- pos1 := 0;
- if (pos1 > (l - 1)) then
- pos1 := (l - 1);
- if (pos2 < 0) then
- pos2 := 0;
- if (pos2 > (l - 1)) then
- pos2 := (l - 1);
- case (pos1 <> pos2) of
- True:
- begin
- SetLength(Result, (IAbs(pos1 - pos2) + 1));
- case (pos1 < pos2) of
- True:
- for i := pos1 to pos2 do
- Result[(i - pos1)] := string(TSA[i]);
- False:
- for i := pos1 downto pos2 do
- Result[(pos1 - i)] := string(TSA[i]);
- end;
- end;
- False: Result := [string(TSA[pos1])];
- end;
- end else
- SetLength(Result, 0);
- end;
- var
- s: string;
- h, i: Integer;
- a, b: TStrArray;
- const
- START = 1;
- FINISH = 8;
- begin
- ClearDebug;
- a := ['Test0', 'Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9'];
- b := TSACopyEx(a, START, FINISH);
- h := High(b);
- for i := 0 to h do
- s := (s + '"' + b[i] + '" ');
- WriteLn('TSACopyEx(a, ' + IntToStr(START) + ', ' + IntToStr(FINISH) + '): ' + s);
- s := '';
- b := TSACopyEx(a, FINISH, START);
- h := High(b);
- for i := 0 to h do
- s := (s + '"' + b[i] + '" ');
- WriteLn('TSACopyEx(a, ' + IntToStr(FINISH) + ', ' + IntToStr(START) + '): ' + s);
- end.
Advertisement
Add Comment
Please, Sign In to add comment