Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Addressbook/Show my entry


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/Show my entry

This example is the version from Sun, 4th Apr 2015.

Project "Show my entry.xojo_binary_project"
Class Window1 Inherits Window
Control lFirst Inherits Label
ControlInstance lFirst Inherits Label
End Control
Control vFirst Inherits Label
ControlInstance vFirst Inherits Label
End Control
Control lLast Inherits Label
ControlInstance lLast Inherits Label
End Control
Control vLast Inherits Label
ControlInstance vLast Inherits Label
End Control
Control lCompany Inherits Label
ControlInstance lCompany Inherits Label
End Control
Control vCompany Inherits Label
ControlInstance vCompany Inherits Label
End Control
Control ljobtitle Inherits Label
ControlInstance ljobtitle Inherits Label
End Control
Control vjobtitle Inherits Label
ControlInstance vjobtitle Inherits Label
End Control
Control lhome Inherits Label
ControlInstance lhome Inherits Label
End Control
Control vhome Inherits Label
ControlInstance vhome Inherits Label
End Control
Control lbirthday Inherits Label
ControlInstance lbirthday Inherits Label
End Control
Control vbirthday Inherits Label
ControlInstance vbirthday Inherits Label
End Control
Control lworkphone Inherits Label
ControlInstance lworkphone Inherits Label
End Control
Control lmobilephone Inherits Label
ControlInstance lmobilephone Inherits Label
End Control
Control vworkphone Inherits Label
ControlInstance vworkphone Inherits Label
End Control
Control vmobilephone Inherits Label
ControlInstance vmobilephone Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control lworkURL Inherits Label
ControlInstance lworkURL Inherits Label
End Control
Control lHomeURL Inherits Label
ControlInstance lHomeURL Inherits Label
End Control
Control vworkURL Inherits Label
ControlInstance vworkURL Inherits Label
End Control
Control vPrivateURL Inherits Label
ControlInstance vPrivateURL Inherits Label
End Control
Control lFlags Inherits Label
ControlInstance lFlags Inherits Label
End Control
Control vFlags Inherits Label
ControlInstance vFlags Inherits Label
End Control
EventHandler Sub Open() a=new ABAddressbookMBS ShowMe ShowAddress ShowPicture End EventHandler
Protected Sub ShowAddress() dim a as ABAddressbookMBS dim p as ABPersonMBS dim s as string dim m as ABMultiValueMBS dim id as string dim index,pindex as integer dim count as integer dim first,last as string dim d as Dictionary dim o as string dim v as Variant dim formattedAddress as NSAttributedStringMBS dim street,zip,city,Country,State as string a=new ABAddressbookMBS p=a.owner if p<>Nil then first=p.valueForProperty(a.kABFirstNameProperty) last=p.valueForProperty(a.kABLastNameProperty) s=first+" "+last+EndOfLine+EndOfLine m=p.valueForProperty(a.kABAddressProperty) if m<>nil then id=m.primaryIdentifier pindex=m.IndexForIdentifier(id) count=m.Count-1 for index=0 to count s=s+"Address "+str(index+1)+":"+chr(13) if index=pindex then s=s+"Primary:"+EndOfLine end if v=m.valueAtIndex(index) if v isa Dictionary then d=v if d.HasKey(a.kABAddressStreetKey) then street=d.Value(a.kABAddressStreetKey) end if if d.HasKey(a.kABAddressZipKey) then zip=d.Value(a.kABAddressZipKey) else zip="" end if if d.HasKey(a.kABAddressCityKey) then city=d.Value(a.kABAddressCityKey) else city="" end if if d.HasKey(a.kABAddressCityKey) then State=d.Value(a.kABAddressCityKey) else State="" end if if d.HasKey(a.kABAddressCountryKey) then Country=d.Value(a.kABAddressCountryKey) else Country="" end if s=s+street+EndOfLine s=s+Zip+" "+City+EndOfLine if state<>"" then // in Germany we don't use the State Value s=s+state+", " end if s=s+country+EndOfLine+EndOfLine if d<>nil then formattedAddress=a.formattedAddressFromDictionary(d) if formattedAddress<>nil then s=s+"Formatted address:"+EndOfLine+"(Mac OS X 10.3 only)"+EndOfLine+formattedAddress.text+EndOfLine+EndOfLine end if end if end if next end if else s="me not set." end if editfield1.text=S End Sub
Protected Sub ShowMe() dim p as ABPersonMBS dim m as ABMultiValueMBS dim st as string dim flags as integer p=a.Owner if p<>nil then // Try to get value in a method and put it into fields trystring(p,a.kABFirstNameProperty,lfirst,vfirst) trystring(p,a.kABLastNameProperty,llast,vlast) trystring(p,a.kABOrganizationProperty,lcompany,vcompany) trystring(p,a.kaBJobTitleProperty,ljobtitle,vjobtitle) if a.kABURLsProperty="" then ' Mac OS X 10.3 trystring(p,a.kABHomePageProperty,lhome,vhome) else ' Mac OS X 10.4 m=p.valueForProperty(a.kABURLsProperty) trylabel(m,a.kABWorkLabel,lworkURL,vworkURL) trylabel(m,a.kABHomeLabel,lHomeURL,vPrivateURL) trylabel(m,a.kABHomePageLabel,lhome,vhome) end if trydate(p,a.kABBirthdayProperty,lbirthday,vbirthday) m=p.valueForProperty(a.kABPhoneProperty) trylabel(m,a.kABPhoneWorkLabel,lworkphone,vworkphone) trylabel(m,a.kABPhoneMobileLabel,lmobilephone,vmobilephone) if a.kABPersonFlags="" then vFlags.text="?" else flags=p.valueForProperty(a.kABPersonFlags) Select case BitwiseAnd(flags,a.kABShowAsMask) case a.kABShowAsPerson st="Person" case a.kABShowAsCompany st="Company" else st="Unkown Show value" end Select Select case BitwiseAnd(flags,a.kABNameOrderingMask) case a.kABFirstNameFirst st=st+", First name sorted first." case a.kABLastNameFirst st=st+", Last name sorted first." case a.kABDefaultNameOrdering 'nothing end Select vFlags.text=str(flags)+": "+st end if else msgBox "Owner not found." end if End Sub
Sub ShowPicture() dim p as ABPersonMBS = a.owner if p<>NIL THEN dim n as NSImageMBS = p.image if n <> nil then dim pic as Picture = n.CopyPictureWithMask canvas1.backdrop=pic end if end if End Sub
Sub trydate(person as abpersonmbs,p as string,label as label,text as label) dim d as Date dim v as Variant dim s as string s=a.LocalizedPropertyOrLabel(p) if s="" then label.text=p else label.text=s end if v=person.valueForProperty(p) if v isa date then d=v text.text=d.longdate else text.text="?" end if End Sub
Sub trylabel(multi as ABMultiValueMBS,p as string,label as label,text as label) dim v as Variant dim index as integer dim i,c as integer v=a.LocalizedPropertyOrLabel(p) if v="" then label.text=p else label.text=V end if if multi<>nil then index=-1 c=multi.Count-1 for i=0 to c if multi.labelAtIndex(i)=p then index=i exit end if next if index>=0 then v=multi.valueAtIndex(index) text.text=v else text.text="?" end if end if End Sub
Sub trystring(person as abpersonmbs,p as String,label as label,text as label) dim s as String s=a.LocalizedPropertyOrLabel(p) if s="" then label.text=p else label.text=s end if dim v as Variant v=person.valueForProperty(p) text.text=v End Sub
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

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


The biggest plugin in space...