Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- COUNT = 2; // Used as the "x" variable for testing - Change to see the effect (1-9).
- {==============================================================================]
- Explanation: Breaks TSA to parts (TSA => ATSA). Contains 2 methods:
- -pm_PartSize (Breaks TSA to ATSA by size of the parts) [x = size]
- -pm_PartAmount (Breaks TSA to ATSA by amount of the parts) [x = amount]
- [==============================================================================}
- function TSAToParts(TSA: TStrArray; method: (pm_PartSize, pm_PartAmount); x: Integer): T2DStrArray;
- var
- a, e, h, h2, i, i2, p, l, z: Integer;
- f: Boolean;
- begin
- h := High(TSA);
- case ((h > -1) and (x > 0)) of
- True:
- begin
- case method of
- pm_PartSize:
- if (x <= h) then
- begin
- Inc(h);
- p := (h div x);
- if ((p * x) < h) then
- Inc(p);
- SetLength(Result, p);
- for i := 0 to (p - 1) do
- for i2 := 0 to (x - 1) do
- begin
- SetLength(Result[i], x);
- if (a < h) then
- begin
- Result[i][i2] := string(TSA[a]);
- Inc(a);
- end else
- begin
- SetLength(Result[i], i2);
- Exit;
- end;
- end;
- end else
- f := True;
- pm_PartAmount:
- case (h <= 0) of
- False:
- begin
- if (h < (x - 1)) then
- x := (h + 1);
- p := Floor((h + 1) / x);
- if (p = 0) then
- p := 1;
- e := ((h + 1) - (p * x));
- if (e >= (h + 1)) then
- e := 0;
- SetLength(Result, x);
- for i := 0 to (x - 1) do
- begin
- if ((e >= (i + 1)) and (e > 0)) then
- SetLength(Result[i], (p + 1))
- else
- if (i <= h) then
- SetLength(Result[i], p);
- h2 := High(Result[i]);
- for i2 := 0 to h2 do
- begin
- Result[i][i2] := string(TSA[a]);
- Inc(a);
- end;
- end;
- end;
- True: f := True;
- end;
- end;
- if f then
- begin
- SetLength(Result, 1);
- l := Length(TSA);
- SetLength(Result[0], l);
- for z := 0 to (l - 1) do
- Result[0][z] := string(TSA[z]);
- end;
- end;
- False: SetLength(Result, 0);
- end;
- end;
- var
- TSA: TStrArray;
- ATSA: T2DStrArray;
- h, i, c: Integer;
- s: string;
- begin
- ClearDebug;
- TSA := ['Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9'];
- ATSA := TSAToParts(TSA, pm_PartAmount, COUNT);
- WriteLn('TSAToParts(TSA, pm_PartAmount, ' + IntToStr(COUNT) + '):');
- h := High(ATSA);
- for i := 0 to h do
- begin
- for c := 0 to High(ATSA[i]) do
- s := (s + '"' + ATSA[i][c] + '" ');
- WriteLn('ATSA[' + IntToStr(i) + ']: ' + Trim(s));
- s := '';
- end;
- WriteLn('');
- ATSA := TSAToParts(TSA, pm_PartSize, COUNT);
- WriteLn('TSAToParts(TSA, pm_PartSize, ' + IntToStr(COUNT) + '):');
- h := High(ATSA);
- for i := 0 to h do
- begin
- for c := 0 to High(ATSA[i]) do
- s := (s + '"' + ATSA[i][c] + '" ');
- WriteLn('ATSA[' + IntToStr(i) + ']: ' + Trim(s));
- s := '';
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment