Jump to content
Janilabo

TSAPick

Recommended Posts

function TSAPick(var TSA: TStrArray; pick_IDs: TIntArray): TStrArray;
var
 h, h2, i, r: Integer;
begin
 TIAUnique(pick_IDs);
 h := High(pick_IDs);
 h2 := High(TSA);
 if ((h2 < 0) or (h < 0)) then
   Exit;
 SetLength(Result, (h2 + 1));
 for i := 0 to h do
   if ((pick_IDs[i] <= h2) and (pick_IDs[i] > -1)) then
   begin
     Result[r] := TSA[pick_IDs[i]];
     Inc(r);
   end;
 SetLength(Result, r);
 if (r <= 0) then
   Exit; 
 SortTIA(pick_IDs);
 for i := h downto 0 do
   if ((pick_IDs[i] <= h2) and (pick_IDs[i] > -1)) then
     Delete(TSA, pick_IDs[i], 1);    
end;

function TSAToStr(TSA: TStrArray): string;
var
 h, i: Integer;
begin
 h := High(TSA);
 if (h < 0) then
   Exit;
 for i := 0 to (h - 1) do
   Result := (Result + '''' + TSA[i] + '''' + ',');
 Result := (Result + '''' + TSA[i] + '''');
end;

var
 TSA: TStrArray;

begin
 ClearDebug;
 TSA := ['TEST1', 'TEST999', 'TEST2', 'TEST3', 'TEST5252', 'TEST4'];
 WriteLn('TSA before picking: ' + TSAToStr(TSA));
 WriteLn('We picked: ' + TSAToStr(TSAPick(TSA, [1, 4])));
 WriteLn('TSA after picking: ' + TSAToStr(TSA));
 SetLength(TSA, 0);
end.

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