Janilabo Posted May 22, 2012 Share Posted May 22, 2012 Breaks TSA to ATSA by amount of "parts". Example Included. TSAToATSAByPartAmount [scar]function TSAToATSAByPartAmount(TSA: TStringArray; amount: Integer): T2DStringArray; var p, h, e, i, i2, h2, a: Integer; begin h := High(TSA); if (h <= 0) or (amount < 2) then begin if (amount = 1) then Result := [TSA] else if amount > 0 then SetLength(Result, Amount); Exit; end; if h < (amount - 1) then amount := (h + 1); p := Floor((h + 1) / amount); if p = 0 then p := 1; e := ((h + 1) - (p * amount)); if e >= (h + 1) then e := 0; SetLength(Result, amount); for i := 0 to (amount - 1) do begin if (e >= (i + 1)) and (e > 0) then SetLength(Result, (p + 1)) else if i <= h then SetLength(Result, p); h2 := High(Result); for i2 := 0 to h2 do begin Result[i2] := TSA[a]; Inc(a); end; end; end; var str: string; TSA: TStringArray; ATSA: T2DStringArray; x, h, h2, i, i2: Integer; begin ClearDebug; TSA := ['Test0', 'Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9', 'Test10', 'Test11', 'Test12', 'Test13', 'Test14', 'Test15', 'Test16', 'Test17', 'Test18', 'Test19', 'Test20']; for x := 10 downto 3 do begin WriteLn('TSAToATSAByPartAmount(TSA, ' + IntToStr(x) + '):'); ATSA := TSAToATSAByPartAmount(TSA, x); h := High(ATSA); for i := 0 to h do begin h2 := High(ATSA); str := ''; str := 'ATSA[' + IntToStr(i) + ']: '; for i2 := 0 to h2 do if (i2 < h2) then str := (str + ATSA[i2] + ', ') else str := (str + ATSA[i2]); WriteLn(str); SetLength(ATSA, 0); end; SetLength(ATSA, 0); WriteLn(''); end; SetLength(TSA, 0); end.[/scar] Quote Link to comment Share on other sites More sharing options...