home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / XLSAdapter / TColInfoListImp.inc < prev    next >
Encoding:
Text File  |  2002-10-05  |  1.8 KB  |  64 lines

  1. //************************************************************************************//
  2. //  File created automatically by GenerateRecords.xls                                 //
  3. //  Do not modify by hand                                                             //
  4. //************************************************************************************//
  5.  
  6. function TColInfoList.GetItems(index: integer): TColInfo;
  7. begin
  8.   Result := inherited Items[Index] as TColInfo;
  9. end;
  10.  
  11. procedure TColInfoList.SetItems(index: integer; const Value: TColInfo);
  12. begin
  13.   inherited Items[Index] := Value;
  14. end;
  15.  
  16. function TColInfoList.Add(aRecord: TColInfo):integer;
  17. begin
  18.   Result:=inherited Add(aRecord);
  19.   Sorted:=false;  //When we add the list gets unsorted
  20. end;
  21.  
  22. procedure TColInfoList.Insert(Index: Integer; ARecord:TColInfo);
  23. begin
  24.   inherited Insert(Index, ARecord);
  25.   // We assume that when we insert, we respect the order, so we dont set Sorted=true
  26. end;
  27.  
  28. function CompareColumns(Item1, Item2: Pointer): Integer;
  29. begin
  30.   if TColInfo(Item1).Column < TColInfo(Item2).Column then Result:=-1 else if TColInfo(Item1).Column > TColInfo(Item2).Column then Result:=1 else Result:=0;
  31. end;
  32.  
  33. procedure TColInfoList.Sort;
  34. begin
  35.   inherited Sort(CompareColumns);
  36.   Sorted:=true;
  37. end;
  38.  
  39. function TColInfoList.Find(const aItem:integer ; var Index: integer): boolean;
  40. Var
  41.  L, H, I, C: Integer;
  42. begin
  43.   if not Sorted then Sort;
  44.   Result := False;
  45.   L := 0;
  46.   H := Count - 1;
  47.   while L <= H do
  48.   begin
  49.     I := (L + H) shr 1;
  50.     if Items[i].Column < aItem then C:=-1 else if Items[i].Column>aItem then C:=1 else C:=0;
  51.     if C < 0 then L := I + 1 else
  52.     begin
  53.       H := I - 1;
  54.       If C = 0 Then
  55.       begin
  56.         Result := True;
  57.         L := I;
  58.       end;
  59.     end;
  60.   end;
  61.   Index := L;
  62. end;
  63.  
  64.