Home > Language Reference > Classes > StreamRecord

UniqueID Property

Unique record identifier

Syntax

Public Property Get UniqueID() As Long
Public Property Let UniqueID(ByVal
lUniqueID As Long)

ParameterDescription
lUniqueIDUnique identifier

Remarks

The system automatically assigns a unique 24 bit identifier to each new record. No other record in the same table can have the same UniqueID. A common application of this property is to express a relationship or join between two tables.

Because this information is stored in the database header, searching on the UniqueID field is much faster than on the other fields because it is not necessary to load the entire record - only its header.

Search for a record in a RecordDB database is possible, using the LookupUniqueID method of the RecordDB class.

In the following example, when the main form in the test application is loaded, we create a database that is populated with 10 records. These records are added to the List1 List, their UniqueID being stored in the ItemData property of each list item.

When the user selects an item in the List, we retrieve its UniqueID and position the cursor on the corresponding record with the LookupUniqueID method of the RecordDB class.

Dim db as new RecordDB
Dim rec as new StreamRecord
Dim OneInteger as Integer
Dim OneString as String

Private Sub Form_Load()
Dim i as Integer
  'create database
  db.OpenByName "TestDB",hbModeCreateAlways+hbModeReadWrite+hbModeShowSecret,"data","ZZZZ"
  'Add records
  For i=0 to 9
    rec.Clear
    rec.Write i
    rec.Write " item " & Cstr(i)
    db.NewRecord rec
  Next i
  db.Close
  
  'Now Read records and fill the list1 object
  db.OpenByName "TestDB",hbModeOpenExisting+hbModeReadWrite,"data","ZZZZ"
  For i=0 to 9
    set rec=db.Record(i)
    rec.Read OneInteger
    rec.Read OneString
    List1.AddItem OneInteger & " : " & OneString ,rec.UniqueID
  Next i
  db.Close
End Sub

Private Sub List1_Change()
Dim lIndex as long
  if List1.ListIndex<0 then Exit sub
  'Open the Database
  db.OpenByName "TestDB",hbModeOpenExisting+hbModeReadWrite,"data","ZZZZ"
  'Move the cursor to the selected UniqueId
  lIndex=db.LookupUniqueID(List1.ItemData(List1.ListIndex))
  'Read the record
  Set rec=db.Record(lIndex)
  rec.Read OneInteger
  rec.Read OneString
  Msgbox "Db cursor moved to record with UniqueId= " & rec.UniqueID  & "\n at index : " & lIndex & "\nRecord Data=" & OneInteger & " and " & OneString
  db.Close
End Sub

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A