Janilabo Posted May 22, 2012 Share Posted May 22, 2012 Breaks TSA to ATSA by size of "parts". Example Included. TSAToATSAByPartSize [scar]function TSAToATSAByPartSize(TSA: TStringArray; partSize: Integer): T2DStringArray; var i, i2, r, h, d: Integer; begin h := High(TSA); if (h >= 0) and (partSize > 0) then if (partSize <= h) then begin Inc(h); r := (h div partSize); if (r * partSize) < h then Inc®; SetLength(Result, r); for i := 0 to (r - 1) do for i2 := 0 to (partSize - 1) do begin SetLength(Result, partSize); if (d < h) then begin Result[i2] := TSA[d]; Inc(d); end else begin SetLength(Result, i2); Exit; end; end; end else Result := [TSA]; 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('TSAToATSAByPartSize(TSA, ' + IntToStr(x) + '):'); ATSA := TSAToATSAByPartSize(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...