We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Obtain property value by name

Eddie Shipman
on
Medium Priority
230 Views
Last Modified: 2013-11-05
Need to access Appointment property by propertyname.
How to do that?

Let's say I want to write a function and pass a property name and then
return the value of the property. VBA will work but I prefer Delphi code...

function getPropValue(Propname: String): Variant;
begin
  Result := AppointmentItem. ?????
end;

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2010

Commented:
Hi, EddieShipman.

Sorry, I don't know Delphi.  The way to do this is to use the ItemProperties collection.  In VBA it would be something like this

Function getPropValue(Appointment As Object, Propname As String) As Variant
    getPropValue = Appointment.ItemProperties.Item(Propname)
End Function

This may not work for all properties.  
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Author

Commented:
Sorry, but ItemProperties is not exposed in the Outlook object model that Delphi uses.
CERTIFIED EXPERT
Top Expert 2010

Commented:
Interesting.  I would have thought there'd be a single object model regardless of language.  
CERTIFIED EXPERT
Top Expert 2010

Commented:
Hello EddieShipman,

One small warning about BDF's (very clever!) approach: if the property returns an object, then at least in
VBA it would cause an error, as object variable require the Set statement, and not the (implicit) Let that
BDF used.

Like BDF, I've never worked in Delphi, so I have no idea whether or not that would be an issue :)

Regards,

Patrick
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Author

Commented:
Yeah, it is when I import the Outlook TypeLib but not in Outlook2000.pas included with Delphi, go figure.

Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Author

Commented:
Now, is this ItemProperties Outlook2007 specific or was it avail in older versions?
CERTIFIED EXPERT
Top Expert 2010

Commented:
It is not specific to Outlook 2007.  I know it is available in 2003 also.  Not sure about Outlook version before that.
CERTIFIED EXPERT
Top Expert 2010

Commented:
Good point, Patrick.
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Author

Commented:
I may be able to access the property using GetIDsofNames and Invoke on the IDispatch of the _AppointmentItem
class.
All-around developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2010

Commented:
Glad you worked it out.  
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.