Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Addressbook/List Addresses
Function:
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/List Addresses
This example is the version from Tue, 30th Jul 2012.
Project "List Addresses.rbp"
Class Window1 Inherits Window
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
EventHandler Sub Open() a=new ABAddressbookMBS dim pa() as ABPersonMBS = a.people for each p as ABPersonMBS in pa dim uid as string = p.valueForProperty(a.kABUIDProperty) list.addrow uid list.cell(list.lastIndex,1)=getaddress(p) next End EventHandler
Function getaddress(p as abpersonmbs) As string dim s as string dim d as Dictionary dim m as ABMultiValueMBS dim id as string dim fn,ln as string dim n as string dim index as integer dim k(-1) as string fn=p.valueForProperty(a.kABFirstNameProperty) ln=p.valueForProperty(a.kABLastNameProperty) if ln<>"" and fn<>"" then k.Append fn+" "+ln else k.Append fn+ln end if // gettting the primary email address is a little bit compilcate: m=p.valueForProperty(a.kABAddressProperty) if m<>Nil then id=m.PrimaryIdentifier if id<>"" then index=m.indexForIdentifier(id) d=m.valueAtIndex(index) if d<>nil then if d.HasKey(a.kABAddressStreetKey) then k.Append d.Value(a.kabAddressStreetKey) end if if d.HasKey(a.kabAddressZIPKey) then if d.HasKey(a.kabAddressCityKey) then k.Append d.Value(a.kabAddressZIPKey)+" "+d.Value(a.kabAddressCityKey) else k.Append d.Value(a.kabAddressZIPKey) end if end if if d.HasKey(a.kabAddressCountryKey) then k.Append d.Value(a.kabAddressCountryKey) end if if d.HasKey(a.kabAddressStateKey) then k.Append d.Value(a.kabAddressStateKey) end if end if end if end if return Join(k,", ") End Function
Property Protected a As abaddressbookMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO=false then MsgBox "This example needs a MachO target running on Mac OS X." quit end if End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.




Links
MBS Xojo PDF Plugins