⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abspage.pas

📁 Absolute Database 是来替代BDE[Borland数据库引擎]的用于Delphi 和 C++ Builder 开发用的数据库引擎. 它小巧, 高速, 健壮, 易于使用. 它能直接编译进
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  FTableStates[Index].TableState := TableState;
end;// SetTableState



////////////////////////////////////////////////////////////////////////////////
//
// TABSPageController
//
////////////////////////////////////////////////////////////////////////////////

//------------------------------------------------------------------------------
// SetPageNo
//------------------------------------------------------------------------------
procedure TABSPageController.SetPageNo(Value: TABSPageNo);
begin
  LPage.PageNo := Value;
end;// SetPageNo


//------------------------------------------------------------------------------
// GetPageNo
//------------------------------------------------------------------------------
function TABSPageController.GetPageNo: TABSPageNo;
begin
  Result := LPage.PageNo;
end;// GetPageNo


//------------------------------------------------------------------------------
// GetPageSize
//------------------------------------------------------------------------------
function TABSPageController.GetPageSize: Integer;
begin
  Result := LPage.PageSize;
end;// GetPageSize


//------------------------------------------------------------------------------
// SetPageBuffer
//------------------------------------------------------------------------------
procedure TABSPageController.SetPageBuffer(Value: TABSPageBuffer);
begin
  LPage.PageBuffer := Value;
end;// SetPageBuffer


//------------------------------------------------------------------------------
// GetPageBuffer
//------------------------------------------------------------------------------
function TABSPageController.GetPageBuffer: TABSPageBuffer;
begin
  Result := LPage.PageBuffer;
end;// GetPageBuffer


//------------------------------------------------------------------------------
// SetOwnBuffer
//------------------------------------------------------------------------------
procedure TABSPageController.SetOwnBuffer(Value: Boolean);
begin
  LPage.OwnBuffer := Value;
end;// SetOwnBuffer


//------------------------------------------------------------------------------
// GetOwnBuffer
//------------------------------------------------------------------------------
function TABSPageController.GetOwnBuffer: Boolean;
begin
  Result := LPage.OwnBuffer;
end;// GetOwnBuffer


//------------------------------------------------------------------------------
// SetIsDirty
//------------------------------------------------------------------------------
procedure TABSPageController.SetIsDirty(Value: Boolean);
begin
  LPage.IsDirty := Value;
end;// SetIsDirty


//------------------------------------------------------------------------------
// GetIsDirty
//------------------------------------------------------------------------------
function TABSPageController.GetIsDirty: Boolean;
begin
  Result := LPage.IsDirty;
end;// GetIsDirty


//------------------------------------------------------------------------------
// SetUseCount
//------------------------------------------------------------------------------
procedure TABSPageController.SetUseCount(Value: Integer);
begin
  LPage.UseCount := Value;
end;// SetUseCount


//------------------------------------------------------------------------------
// GetUseCount
//------------------------------------------------------------------------------
function TABSPageController.GetUseCount: Integer;
begin
  Result := LPage.UseCount;
end;// GetUseCount


//------------------------------------------------------------------------------
// GetPageManager
//------------------------------------------------------------------------------
function TABSPageController.GetPageManager: TABSPageManager;
begin
  Result := LPage.PageManager;
end;// GetPageManager


//------------------------------------------------------------------------------
// GetPageData
//------------------------------------------------------------------------------
function TABSPageController.GetPageData: TABSPageBuffer;
begin
  Result := LPage.PageData;
end;// GetPageData


//------------------------------------------------------------------------------
// GetPageDataSize
//------------------------------------------------------------------------------
function TABSPageController.GetPageDataSize: Integer;
begin
  Result := LPage.PageDataSize;
end;// GetPageDataSize


//------------------------------------------------------------------------------
// EnlargePageBuffer
//------------------------------------------------------------------------------
procedure TABSPageController.EnlargePageBuffer(NewSize: Integer);
begin
  LPage.EnlargePageBuffer(NewSize);
end;// EnlargePageBuffer



////////////////////////////////////////////////////////////////////////////////
//
// TABSSortedPageList
//
////////////////////////////////////////////////////////////////////////////////


//------------------------------------------------------------------------------
// Construct array of specified size
//------------------------------------------------------------------------------
constructor TABSSortedPageList.Create(size: integer);
begin
 AllocBy := 1000; // default alloc
 deAllocBy := 1000; // default dealloc
 MaxAllocBy := 10000; // max alloc
 AllocItemCount := 0;
 LRUCount := 0;
 SetSize(size);
end;//Create


//------------------------------------------------------------------------------
// Delete an element by specified key
//------------------------------------------------------------------------------
procedure TABSSortedPageList.Delete(PageNo: integer);
var pos : Integer;
begin
 if (itemCount <= 0) then
  raise EABSException.Create(20165, ErrorADeleteFromArray);
 if (itemCount = 1) then
  DeleteByPosition(0)
 else
  begin
   pos := FindPosition(PageNo);
   if (pos < 0) then
     raise EABSException.Create(20166, ErrorADeleteFromArrayNotFound, [PageNo, itemCount]);
   DeleteByPosition(pos);
  end;
end;//Delete


//------------------------------------------------------------------------------
// Clear
//------------------------------------------------------------------------------
procedure TABSSortedPageList.Clear;
begin
  ItemCount := 0;
end;// Clear


//------------------------------------------------------------------------------
// FirstByLRU
//------------------------------------------------------------------------------
function TABSSortedPageList.FirstByLRU: TABSPage;
var
  bInit: Boolean;
  i: Integer;
begin
  bInit := False;
  Result := nil;
  for i := 0 to ItemCount-1 do
   if ((not bInit) or (ValueItems[i].LRUCount < LRULastFound)) then
     begin
       bInit := True;
       LRULastFound := ValueItems[i].LRUCount;
       Result := ValueItems[i].Page;
     end;
end;// FirstByLRU


//------------------------------------------------------------------------------
// NextByLRU
//------------------------------------------------------------------------------
function TABSSortedPageList.NextByLRU: TABSPage;
var
  i: Integer;
begin
  Result := nil;
  for i := 0 to ItemCount-1 do
   if (ValueItems[i].LRUCount < LRULastFound) then
     begin
       LRULastFound := ValueItems[i].LRUCount;
       Result := ValueItems[i].Page;
       break;
     end;
end;// NextByLRU


//------------------------------------------------------------------------------
// UpdateLRU
//------------------------------------------------------------------------------
procedure TABSSortedPageList.UpdateLRU(Page: TABSPage);
var
  pos: Integer;
begin
  pos := FindPosition(Page.PageNo);
  if (Pos = - 1) then
    raise EABSException.Create(20167, ErrorAPageNotFound);
  Inc(LRUCount);
  ValueItems[Pos].LRUCount := LRUCount;
end;// UpdateLRU


//------------------------------------------------------------------------------
// Delete an element at specified position
//------------------------------------------------------------------------------
procedure TABSSortedPageList.DeleteByPosition(ItemNo: integer);
begin
 if (itemNo < itemCount-1) then
  begin
   Move(KeyItems[itemNo+1],KeyItems[itemNo],
       (itemCount - itemNo-1) * sizeOf(integer));
   Move(ValueItems[itemNo+1],ValueItems[itemNo],
       (itemCount - itemNo-1) * sizeOf(ValueItems[0]));
  end;
 dec(ItemCount);
 SetSize(ItemCount);
end;//DeleteByPosition


//------------------------------------------------------------------------------
// Finds value for specified key
// returns nil if element was not found
//------------------------------------------------------------------------------
function TABSSortedPageList.Find(key: Integer): TABSPage;
var
  pos: Integer;
begin
 pos := FindPositionForInsert(key);
 if (pos >= itemCount) or (pos < 0) then
  Result := nil
 else
  if (KeyItems[pos] <> key) then
   Result := nil
 else
  Result := ValueItems[pos].Page;
end;//Find


//------------------------------------------------------------------------------
// Finds position for insert element
// returns -1 if element was not found
//------------------------------------------------------------------------------
function TABSSortedPageList.FindPosition(key: Integer): Integer;
begin
 Result := FindPositionForInsert(key);
 if (Result >= itemCount) or (Result < 0) then
  Result := -1
 else
  if (KeyItems[Result] <> key) then
   Result := -1;
end;//FindPosition


//------------------------------------------------------------------------------
// Finds position for insert element
//------------------------------------------------------------------------------
function TABSSortedPageList.FindPositionForInsert(key: Integer): Integer;
var i,dx,f,
    oldRes,res : Integer;
begin
 i := itemCount shr 1;
 dx := i;
 Result := itemCount;
 if (itemCount > 0) then
 begin
  f := 0;
  res := 2;
  while (true) do
   begin
    dx := dx shr 1;
    if (dx < 1) then dx := 1;
     oldRes := res;
     // compare, ascending
     if (KeyItems[i] = key) then
      res := 0
     else
      if (KeyItems[i] < key) then
       res := 1
      else
       res := -1;
    if (res < 0) then
     begin
      //  element, specified by value should be higher then current element (+->0)
      i := i - dx;
     end
    else
    if (res > 0) then
     begin
      //  element, specified by value should be lower then current element (+->0)
      i := i + dx;
     end
    else // values are equal
     begin
      Result := i;
      break;
     end;
    if  (i < 0) and (dx = 1) then
     begin
      Result := 0;
      break;
     end;
    if  (i > itemCount-1) and (dx = 1) then
     begin
      Result := itemCount;
      break;
     end;

    if  (i > itemCount-1) then
     i := itemCount-1;
    if  i < 0 then
     i := 0;

    if (dx = 1) and (f > 1) then
     begin
      // dx minimum
      // compare, ascending
      if (KeyItems[i] = key) then
       res := 0
      else
       if (KeyItems[i] < key) then
        res := 1
       else
        res := -1;

      if (res < 0) and (oldRes > 0) then
       Result := i;
      if (res > 0) and (oldRes < 0) then
       Result := i+1;
      if (res = oldRes) then
       continue;
      break;
     end;// last step
    if (res <> oldRes) and (dx = 1) and (oldRes <> 2) then
     inc(f);
  end;//while dx
 end; // if itemCount > 0
end;//FindPositionForInsert


//------------------------------------------------------------------------------
// Insert an element into specified position
//------------------------------------------------------------------------------
procedure TABSSortedPageList.Insert(Page: TABSPage);
var
  pos : Integer;
  value: TABSPageElement;
begin
 Inc(LRUCount);
 value.Page := Page;
 value.LRUCount := LRUCount;
 if (itemCount <= 0) then
  InsertByPosition(0,Page.PageNo,value)
 else
  if (itemCount = 1) then
   begin
    if (KeyItems[0] <= Page.PageNo) then
     InsertByPosition(1,Page.PageNo,value)
    else
     InsertByPosition(0,Page.PageNo,value);
   end
  else
   begin
    pos := FindPositionForInsert(Page.PageNo);
    InsertByPosition(pos,Page.PageNo,value);
   end;
end;//Insert


//------------------------------------------------------------------------------
// Insert an element into specified position
//------------------------------------------------------------------------------
procedure TABSSortedPageList.InsertByPosition(ItemNo, key: integer; var value: TABSPageElement);
begin
 inc(ItemCount);
 SetSize(ItemCount);
 if (itemCount <= 1) then
  begin
   KeyItems[0] := key;
   ValueItems[0] := value;
  end
 else
 if (itemNo >= itemCount-1)
  then
   begin
    KeyItems[itemCount-1] := key;
    ValueItems[itemCount-1] := value;
   end
  else
   begin
    Move(KeyItems[itemNo],KeyItems[itemNo+1],
        (itemCount - itemNo-1) * sizeOf(integer));
    Move(ValueItems[itemNo],ValueItems[itemNo+1],
        (itemCount - itemNo-1) * sizeOf(ValueItems[0]));
    KeyItems[itemNo] := key;
    ValueItems[itemNo] := value;
   end;
end;//InsertByPosition


//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -