Jump to content
Janilabo

TSAToATSAByPartAmount

Recommended Posts

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]

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...