Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • 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
EddieShipman
Asked:
EddieShipman
  • 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
 
EddieShipmanAuthor 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

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

0
 
EddieShipmanAuthor 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
 
EddieShipmanAuthor Commented:
I may be able to access the property using GetIDsofNames and Invoke on the IDispatch of the _AppointmentItem
class.
0
 
EddieShipmanAuthor 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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