Jump to content
Janilabo

TSAAllSame

Recommended Posts

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

 

TSAAllSame

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

var

h, i: Integer;

begin

h := High(TSA);

if (h < 1) then

begin

Result := (h = 0);

Exit;

end;

for i := 1 to h do

if (TSA <> TSA[0]) then

Exit;

Result := True;

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 TSAAllSame(ATSA) then

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

else

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

SetLength(ATSA, 0);

end;

SetLength(ATSA, 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...