• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Obtain property value by name

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
Eddie Shipman
Asked:
Eddie Shipman
  • 5
  • 5
1 Solution
 
David LeeCommented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
Sorry, but ItemProperties is not exposed in the Outlook object model that Delphi uses.
0
 
David LeeCommented:
Interesting.  I would have thought there'd be a single object model regardless of language.  
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
Patrick MatthewsCommented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
Yeah, it is when I import the Outlook TypeLib but not in Outlook2000.pas included with Delphi, go figure.

0
 
Eddie ShipmanAll-around developerAuthor Commented:
Now, is this ItemProperties Outlook2007 specific or was it avail in older versions?
0
 
David LeeCommented:
It is not specific to Outlook 2007.  I know it is available in 2003 also.  Not sure about Outlook version before that.
0
 
David LeeCommented:
Good point, Patrick.
0
 
Eddie ShipmanAll-around developerAuthor Commented:
I may be able to access the property using GetIDsofNames and Invoke on the IDispatch of the _AppointmentItem
class.
0
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
David LeeCommented:
Glad you worked it out.  
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now