Jump to content
Janilabo

TSAToATSAByPartSize

Recommended Posts

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]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...