Keychain.Constructor(index as Integer)
From Xojo Documentation
Constructor
This method is only available on the macOS platform. For cross-platform compatibility, use #If...#Endif with the Target... specifiers to make sure you will not attempt to use this method on an incompatible platform. |
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.
#If TargetMacOS
Declare Function KCGetKeychainName Lib "Carbon" (keychain As Integer, keychainName As Ptr) As Integer
Var i As Integer
Var err As Integer
Var kc As Keychain
Var kcName As MemoryBlock
kcName = New MemoryBlock(256)
For i = 0 To System.KeychainCount - 1
kc = New Keychain(i)
If kc = Nil Then
MessageBox("Keychain(" + Str(i) + ") returned nil")
Else
err = KCGetKeychainName(kc.Handle, kcName)
If err <> 0 Then
MessageBox("KCGetKeychainName returned " + Str(err))
Else
ListBox1.AddRow(kcName.PString(0))
End If
End If
Next
#Endif
Declare Function KCGetKeychainName Lib "Carbon" (keychain As Integer, keychainName As Ptr) As Integer
Var i As Integer
Var err As Integer
Var kc As Keychain
Var kcName As MemoryBlock
kcName = New MemoryBlock(256)
For i = 0 To System.KeychainCount - 1
kc = New Keychain(i)
If kc = Nil Then
MessageBox("Keychain(" + Str(i) + ") returned nil")
Else
err = KCGetKeychainName(kc.Handle, kcName)
If err <> 0 Then
MessageBox("KCGetKeychainName returned " + Str(err))
Else
ListBox1.AddRow(kcName.PString(0))
End If
End If
Next
#Endif