Solved

Obtain property value by name

Posted on 2009-07-08
11
199 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

0
Comment
Question by:EddieShipman
  • 5
  • 5
11 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24805692
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.  
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 24806061
Sorry, but ItemProperties is not exposed in the Outlook object model that Delphi uses.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24806202
Interesting.  I would have thought there'd be a single object model regardless of language.  
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24806382
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
0
 
LVL 26

Author Comment

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

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 24807340
Now, is this ItemProperties Outlook2007 specific or was it avail in older versions?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24808940
It is not specific to Outlook 2007.  I know it is available in 2003 also.  Not sure about Outlook version before that.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24808963
Good point, Patrick.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 24809086
I may be able to access the property using GetIDsofNames and Invoke on the IDispatch of the _AppointmentItem
class.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 0 total points
ID: 24813808
Here's how to do it in Delphi:

const
  EmptyDispParams: TDispParams = (rgvarg: nil; rgdispidNamedArgs: nil; cArgs: 0; cNamedArgs: 0);
 
var
  iLCID: Integer;  // you might init this to LOCALE_USER_DEFAULT
 
function GetDispId(const Obj: IDispatch; const Member: WideString; DispIdPtr: PInteger): Boolean;
begin
  Result := Succeeded(Obj.GetIdsOfNames(GUID_NULL, @Member, 1, iLCID, DispIdPtr));
end;
 
function InvokePropertyGet(const Obj: IDispatch; Name: WideString):Variant;
var
  TheDispId, ArgErr: Integer;
  DispParams: TDispParams;
begin
  if GetDispId(Obj, Name, @TheDispId) then
    begin
      DispParams := EmptyDispParams;
      OleCheck(Obj.Invoke(TheDispId,
                          GUID_NULL,
                          iLCID,
                          DISPATCH_PROPERTYGET,
                          DispParams,
                          @Result,
                          nil,
                          @ArgErr));
    end;
end;
 
 
// Usage:
 
var
  AApptCompareFieldValue: Variant;
  OutlookPropertyName: WideString;  
begin
  iLCID := LOCALE_USER_DEFAULT;
  OutlookPropertyName := 'LastModificationTime';
  AApptCompareFieldValue := InvokePropertyGet(AOutlookAppointmentItem, OutlookPropertyName);
  Showmessage(AApptCompareFieldValue);
end;
  

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 24814752
Glad you worked it out.  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question