Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Obtain property value by name

Posted on 2009-07-08
11
Medium Priority
?
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 93

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

705 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