Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Moves oldIndex to newIndex in TSA. Returns true, if movement was succesfully done!
- [==============================================================================}
- function TSAMove(var TSA: TStrArray; oldIndex, newIndex: Integer): Boolean;
- var
- h, i: Integer;
- begin
- h := High(TSA);
- Result := ((h > 0) and (oldIndex <> newIndex) and InRange(oldIndex, 0, h) and InRange(newIndex, 0, h));
- if Result then
- case (oldIndex > newIndex) of
- True:
- for i := oldIndex downto (newIndex + 1) do
- Swap(TSA[i], TSA[(i - 1)]);
- False:
- for i := oldIndex to (newIndex - 1) do
- Swap(TSA[i], TSA[(i + 1)]);
- end;
- end;
- var
- s: string;
- h, i: Integer;
- a: TStrArray;
- begin
- ClearDebug;
- a := ['Test1', 'Test2', 'Test3', 'Test4', 'Test0'];
- TSAMove(a, 4, 0);
- h := High(a);
- for i := 0 to h do
- s := (s + '"' + a[i] + '" ');
- WriteLn('a: ' + s);
- end.
Advertisement
Add Comment
Please, Sign In to add comment