Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/Addressbook/Addressbook Pick one address
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Addressbook/Addressbook Pick one address
This example is the version from Thu, 4th Mar 2015.
Project "Addressbook Pick one address.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action()
p.Visible=me.Value
End EventHandler
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim ca() as ABRecordMBS = p.SelectedRecords
if UBound(ca)<0 then
MsgBox "Please select a person first!"
else
dim ap as ABPersonMBS = ABPersonMBS(ca(0))
dim s as string = ap.vCardRepresentation
s=Replaceall(s,chr(10),"")
MsgBox s
end if
End EventHandler
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
End Control
EventHandler Sub Close()
if p<>nil then
p.Visible=false
p.RemoveEvents
end if
End EventHandler
EventHandler Sub Open()
if TargetMachO then
a=new ABAddressbookMBS
p=new MyPicker
if p.Available=false then
MsgBox "This demo requires Mac OS X 10.3!"
quit
Return
end if
p.Create
p.InstallEvents self
p.Width=500
p.Height=300
p.Visible=true
p.AddProperty a.kABAddressProperty
p.AllowSingleValueSelection=true
CheckBox1.Value=p.Visible
else
MsgBox "This example needs a MachO target."
end if
End EventHandler
Property a As abaddressbookMBS
Property p As abpickerMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
#if TargetCocoa then
MsgBox "This example is for Mac OS X with Carbon only."
#elseif TargetCarbon then
// ok
#else
MsgBox "This example is for Mac OS X with Carbon only."
#endif
End EventHandler
End Class
Class MyPicker Inherits ABPickerMBS
EventHandler Sub GroupDoubleClicked()
MainWindow.List.InsertRow 0,"Group Double Clicked"
End EventHandler
EventHandler Sub GroupSelectionChanged()
MainWindow.List.InsertRow 0,"Group Selection Changed"
End EventHandler
EventHandler Sub NameDoubleClicked()
MainWindow.List.InsertRow 0,"Name Double Clicked"
dim c as integer
dim t as string
dim a as ABAddressBookMBS=MainWindow.a
dim s() as Variant = me.SelectedValues
c=UBound(s)
if c>=0 then
// pick first, newer Mac OS X gives formatted text of address, older ones give dictionary...
if s(0) isa Dictionary then
dim d as Dictionary=s(0)
t=t+d.Lookup(a.kABAddressStreetKey,"")+EndOfLine
t=t+d.Lookup(a.kABAddressZIPKey,"")+" "
t=t+d.Lookup(a.kABAddressCityKey,"")+EndOfLine
t=t+d.Lookup(a.kABAddressCountryKey,"")+EndOfLine
elseif VarType(s(0)) = Variant.TypeString then
t = s(0)
end if
end if
MainWindow.EditField1.text=t
End EventHandler
EventHandler Sub NameSelectionChanged()
MainWindow.List.InsertRow 0,"Name Selection Changed"
End EventHandler
EventHandler Sub ValueSelectionChanged()
MainWindow.List.InsertRow 0,"Value Selection Changed"
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacCocoa Plugin.