Jump to content
Janilabo

TSAAllUnique

Recommended Posts

Returns true if all the values of string array are unique to each other. Example included.

 

TSAAllUnique

[scar]function TSAAllUnique(TSA: TStringArray): Boolean;

var

h, i, i2: Integer;

begin

h := High(TSA);

if (h < 1) then

begin

Result := (h = 0);

Exit;

end;

for i := 0 to (h - 1) do

for i2 := (i + 1) to h do

if (i <> i2) then

begin

Result := (TSA <> TSA[i2]);

if not Result then

Exit;

end;

end;

 

var

ATSA: T2DStringArray;

h, i: Integer;

 

begin

ClearDebug;

SetLength(ATSA, 9);

ATSA[0] := ['Test0', 'Test1', 'Test2', 'Test3'];

ATSA[1] := ['Test0', 'Test1', 'Test2', 'Test1'];

ATSA[2] := ['Test0', 'Test1', 'Test2', 'Test2'];

ATSA[3] := ['Test0', 'Test1', 'Test1', 'Test2'];

ATSA[4] := ['Test0', 'Test1', 'Test1', 'Test1'];

ATSA[5] := ['Test1', 'Test1', 'Test1', 'Test1'];

ATSA[6] := ['Test1', 'Test2', 'Test3', 'Test4'];

ATSA[7] := ['Test'];

ATSA[8] := [];

h := High(ATSA);

for i := 0 to h do

begin

if TSAAllUnique(ATSA) then

WriteLn('ATSA[' + IntToSTr(i) + ']: ALL values are unique!')

else

WriteLn('ATSA[' + IntToStr(i) + ']: ALL values are NOT unique.');

SetLength(ATSA, 0);

end;

SetLength(ATSA, 0);

end.[/scar]

Edited by Janilabo
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...