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


type 
	TCustRec = record 
		crSurname : string[63]; 
		crForname : string[63]; 
		crAddr1   : string[63]; 
		crAddr2   : string[63]; 
		crCity    : string[31]; 
		crState   : string[2]; 
		crZipCode : string[5]; 
	end; 
var 
	RecordFile : TaaRecordStream; 
	IndexFile  : TaaBtree; 
	Rec        : TCustRec; 
	RecNo 	   : integer; 
begin 
	// create both files 
	RecordFile := TaaRecordStream.CreatFile( 'customer.dat' ,  
		true , sizeof(TCustrec) ); 
	IndexFile := TaaBtree.CreateFile( 'Customer.inx' , true , 
		128 ); 
	// add a few reocrds 
	FillChar( Rec , sizeof(Rec) , 0 ); 
	Rec.crSurname := 'Jones'; 
	Rec.crForname := 'Gertrude'; 
	// ...set other fields... 
	// add this record 
	RecNo := RecordFile.Add( Rec ); 
	// add the surname as a key to the index 
	IndexFile.AddKey( Rec.crSurname , RecNo ); 
	Rec.crSurname := 'Smith'; 
	Rec.crForname := 'Desdemona'; 
	// ...set other fields... 
	// add this record 
	RecNo := RecordFile.Add( Rec ); 
	IndexFile.AddKey( Rec.crSurname , RecNo ); 
	Rec.crSurname := 'Brown'; 
	Rec.crForname := 'Oleanna'; 
	// ...set other fields... 
	// add this record 
	RecNo := RecordFile.Add( Rec ); 
	IndexFile.AddKey( Rec.crSurname , RecNo ); 
	// find and read 'Smith' 
	if IndexFile.FindKey( 'Smith' , RecNo ) then 
		RecordFile.Read( RecoNo , Rec ); 
	// delete 'Brown' from index and record file 
	if Indexfile.FindKey( 'Brown' , RecNo ) then begin 
		IndexFile.DeleteKey( 'Brown' , RecNo ); 
		RecordFile.Delete( Recno ); 
	end; 
	IndexFile.Free; 
	RecordFile.Free; 
end.