Solved

Obtain property value by name

Posted on 2009-07-08
11
195 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
If you don't know how to downgrade, my instructions below should be helpful.
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

911 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

21 Experts available now in Live!

Get 1:1 Help Now