www.pudn.com > GOOGLE.rar > 1.pas, change:2002-02-05,size:1211b


procedure TaaBtreePage.DeleteKey( const aKey : string; aRecLink : integer ); 
var 
	FoundIt : boolean; 
	L, R, M : integer; 
	Compare : integer; 
begin 
	{perform a binary search for the key} 
	FoundIt := false; 
	if ( FKeyCount > 0 ) then begin 
		L := 0; 
		R := pred( FKeyCount ); 
		while ( L <= R ) do begin 
			M := ( L + R ) div 2; 
			Compare := CompareStr( aKey , FKeys[M] ); 
			if ( Compare = 0 ) and ( aRecLink <> -1 ) then 
				if( aRecLink = FRecLinks[m] ) then 
					Compare := 0 
				else if ( aRecLink < FrecLinks[M] ) then 
					Compare := -1 
				else 
					Compare := 1; 
			if( Compare = 0 ) then begin 
				FoundIt := true; 
				Break; 
			end; 
			if( ( Compare < 0 ) then 
				R := M - 1; 
			else 
				L := M + 1; 
		end; 
		{if we found it, it can be found at index M...} 
		if FoundIt then begin 
			{delete the key, its record link and its page link} 
			FKeys.Delete(M); 
			dec(FKeyCount); 
			if( M <> FKeyCount ) then begin 
				Move( FRecLinks[M+1] , FRecLinks[M] ,  
(FKeuCount - M) * sizeof(longint)); 
				Move( FPageLinks[M+2] , FPageLinks[M+1] ,  
(FKeyCount - M) * sizeof(longint)); 
			end; 
			{update the stream with the change page} 
			bpWrite; 
		end; 
	end; 
end;