Solved

Obtain property value by name

Posted on 2009-07-08
11
194 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Use email signature images to promote corporate certifications and industry awards.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

760 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

16 Experts available now in Live!

Get 1:1 Help Now