KeyChain.Constructor(index as Integer)

From Xojo Documentation

Constructor


KeyChain.Constructor()

Gives you a reference to any KeyChain known by the KeyChain manager. The Index value should be in the range from 0 to System.KeyChainCount.

Example

This constructor is in a For loop that instantiates a KeyChain for each for each KeyChain item. It populates a ListBox with the list of keychains. It is in the Open event of the app.

#If TargetMacOS
Declare Function KCGetKeychainName Lib "Carbon" (keychain As Integer, keychainName As Ptr) As Integer

Dim i As Integer
Dim err As Integer
Dim kc As KeyChain
Dim kcName As MemoryBlock

kcName = New MemoryBlock(256)

For i = 0 To System.KeyChainCount - 1
kc = New KeyChain(i)

If kc = Nil Then
MsgBox("Keychain(" + Str(i) + ") returned nil")
Else
err = KCGetKeychainName(kc.Handle, kcName)

If err <> 0 Then
MsgBox("KCGetKeychainName returned " + Str(err))
Else
ListBox1.AddRow(kcName.PString(0))
End If
End If
Next
#Endif