Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MoveTPA(var arr: TPointArray; oldIndex, newIndex: Integer): Boolean;
- var
- h, i: Integer;
- t: TPoint;
- begin
- h := High(arr);
- if ((h > 0) and InRange(oldIndex, 0, h)) then
- begin
- if (newIndex < 0) then
- newIndex := 0
- else
- if (newIndex > h) then
- newIndex := h;
- Result := (oldIndex <> newIndex);
- if Result then
- begin
- t := arr[oldIndex];
- if (oldIndex > newIndex) then
- for i := oldIndex downto (newIndex + 1) do
- arr[i] := arr[(i - 1)]
- else
- for i := oldIndex to (newIndex - 1) do
- arr[i] := arr[(i + 1)];
- arr[newIndex] := t;
- end;
- end else
- Result := False;
- end;
- var
- TPA: TPointArray;
- begin
- TPA := [Point(0, 1), Point(2, 3), Point(4, 5), Point(6, 7), Point(8, 9)];
- WriteLn('BEFORE: ' + ToStr(TPA));
- MoveTPA(TPA, 1, 4);
- WriteLn('AFTER: ' + ToStr(TPA));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement