VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Foods"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'Klasa Foods
Implements DBTable
Private db As DBase
Private tbNames As Collection
Private rec As Recordset
Private opened As Boolean

Private Sub DBTable_addTableValue(nm As String)
  Dim tbn As String
  On Local Error GoTo noname
  tbn = tbNames(nm)
sbexit:
  Exit Sub
noname:
  tbNames.Add nm, nm
  Resume sbexit
End Sub

Private Sub DBTable_createTable(datab As DBase)
  Dim inx As Indexer
  Set db = datab
  Set tbNames = New Collection
  Set inx = db.makeTable("Foods")
  inx.createKey "Foodkey"
  inx.createText "Foodname", 20
  inx.makeIndex "Foodname", False
  inx.addTable
End Sub

Private Function DBTable_getKey(nm As String) As Integer
 DBTable_openTable
 rec.Index = "FoodName"
 rec.Seek nm, adSeekFirstEQ
 If Not rec.EOF Then
    DBTable_getKey = rec![foodkey]
 Else
   DBTable_getKey = 0
 End If
End Function

Private Function DBTable_getValue() As String
  DBTable_getValue = rec![Foodname]
  rec.MoveNext
End Function

Private Function DBTable_hasMoreElements() As Boolean
  DBTable_hasMoreElements = Not rec.EOF
End Function

Private Sub DBTable_makeTable()
  Dim i As Integer, nm As String
  DBTable_openTable
  For i = 1 To tbNames.Count
    nm = tbNames(i)
    rec.AddNew
    rec![Foodname] = nm
    rec.Update
  Next i
End Sub

Private Sub DBTable_moveFirst()
  rec.moveFirst
End Sub

Private Sub DBTable_openTable()
  If Not opened Then
    Set rec = db.openTable("Foods")
    opened = True
  End If
End Sub

Private Sub DBTable_setDB(datab As DBase)
  Set db = datab
End Sub
