;Example of bdbfs plugin file.
;Compares two bases on current order field and mark
;all non-unique (in first of them) records as deleted.
;See also app_new.ini.
;Uses also some elements of bdbfs visual interface.

#include clipper.ch
#include bdbfs.ch

LOCAL _ik, xVal, nRec, nDel
cCodePage:='cp866'
_ik:=IndexKey(0)
;indexKey() expression should be correct for both tables

IF Empty(_ik)
	SHOW 'Table is not ordered'
	#BREAK
ENDIF

IF !FileExist("OTHER.DBF")
	SHOW 'OTHER.DBF is absent'
	#BREAK
ENDIF

nRec:=RECNO()
nDel:=0

SELECT 2
USE HERE other
START SEARCH
WHILE !EOF() .AND. CheckEsc()	//Esc=Abort
	xVal := &_ik
	SELECT 1
	IF DBSEEK(xVal) .AND. !DELETED()
		nDel:=nDel+1
		DELETE
	ENDIF
	SELECT 2
	SKIP
ENDWHILE
END METER
SHOW WITH BELL NTRIM(nDel)+' records deleted'

CLOSE 2

SELECT 1
DBGOTO(nRec)

DISABLE REOPEN		//Disable main file Re-Open
