[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'System' (#rtl)

CompareWord

Compare 2 memory buffers word per word

Declaration

Source position: systemh.inc line 383

function CompareWord(

  const buf1;

  const buf2;

  len: SizeInt

):SizeInt;

Description

CompareWordcompares two memory regions buf1,buf2on a Word-per-Word basis for a total of lenWords. (A Word is 2 bytes).

The function returns one of the following values:

-1
if buf1and buf2contain different Words in the first lenWords, and the first such Word is smaller in buf1than the Word at the same position in buf2.
0
if the first lenWords in buf1and buf2are equal.
1
if buf1and buf2contain different Words in the first lenWords, and the first such Word is larger in buf1than the Word at the same position in buf2.

Errors

None.

See also

CompareChar

  

ompare 2 memory buffers character per character

CompareByte

  

Compare 2 memory buffers byte per byte

CompareDWord

  

Compare 2 memory buffers DWord per DWord

Example

Program Example102;

{ Program to demonstrate the CompareWord function. }

Const
  ArraySize     = 100;
  HalfArraySize = ArraySize Div 2;

Var
  Buf1,Buf2 : Array[1..ArraySize] of Word;
  I : longint;

  Procedure CheckPos(Len : Longint);

  Begin
    Write('First ',Len,' words are ');
    if CompareWord(Buf1,Buf2,Len)<>0 then
      Write('NOT ');
    Writeln('equal');
  end;


begin
  For I:=1 to ArraySize do
    begin
    Buf1[i]:=I;
    If I<=HalfArraySize Then
      Buf2[I]:=I
    else
      Buf2[i]:=HalfArraySize-I;
    end;
  CheckPos(HalfArraySize div 2);
  CheckPos(HalfArraySize);
  CheckPos(HalfArraySize+1);
  CheckPos(HalfArraySize + HalfArraySize Div 2);
end.