// We assume that when we insert, we respect the order, so we dont set Sorted=true
end;
function CompareShapes(Item1, Item2: Pointer): Integer;
begin
if TEscherSPRecord(Item1).ShapeId^ < TEscherSPRecord(Item2).ShapeId^ then Result:=-1 else if TEscherSPRecord(Item1).ShapeId^ > TEscherSPRecord(Item2).ShapeId^ then Result:=1 else Result:=0;
end;
procedure TEscherShapeCache.Sort;
begin
inherited Sort(CompareShapes);
Sorted:=true;
end;
function TEscherShapeCache.Find(const aItem:Cardinal ; var Index: integer): boolean;
Var
L, H, I, C: Integer;
begin
if not Sorted then Sort;
Result := False;
L := 0;
H := Count - 1;
while L <= H do
begin
I := (L + H) shr 1;
if Items[i].ShapeId^ < aItem then C:=-1 else if Items[i].ShapeId^>aItem then C:=1 else C:=0;