Solved

Obtain property value by name

Posted on 2009-07-08
11
196 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Read this checklist to learn more about the 15 things you should never include in an email signature.
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now