Obtain property value by name

M

MB34

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:
{Delphi}
function getPropValue(Propname: String): Variant;
begin
Result := AppointmentItem. ?????
end;
 
M

Michael Bauer [MVP - Outlook]

You need to handle every supported case, e.g.:

Select Case Propname
Case "Start": getPropValue=Item.Start
Case "Subject": getPropValue=Item.Subject
End Select

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 8 Jul 2009 08:25:21 -0700 (PDT) schrieb MB34:
 
M

MB34

Need to access Appointment property by propertyname.
You need to handle every supported case, e.g.:

Select Case Propname
Case "Start": getPropValue=Item.Start
Case "Subject": getPropValue=Item.Subject
End Select

You mean that there is no way without handling each property in a case
statement?
The Delphi Outlook object model does not expose the ItemProperties
either.
 
M

MB34

Or use Item.ItemProperties.Item("property name") for simple, non-object
properties.

Thanks, Michael and Sue...

The Delphi Outlook object model does not expose the ItemProperties
either.

In the included Outlook2000.pas file, ItemProperties is not exposed so
I am able to get
it by using the code below instead of either modifying the
Outlook2000.pas file or importing
the Outlook TLB on my system.

const
EmptyDispParams: TDispParams = (rgvarg: nil; rgdispidNamedArgs: nil;
cArgs: 0; cNamedArgs: 0);

var
intLCID: Integer;

function GetDispId(const Obj: IDispatch; const Member: WideString;
DispIdPtr: PInteger): Boolean;
begin
Result := Succeeded(Obj.GetIdsOfNames(GUID_NULL, @Member, 1,
intLCID, 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,
intLCID,
DISPATCH_PROPERTYGET,
DispParams,
@Result,
nil,
@ArgErr));
end;
end;


// Usage:

var
AApptCompareFieldValue: Variant;
OutlookPropertyName: WideString;
begin
intLCID := LOCALE_USER_DEFAULT;
OutlookPropertyName := 'LastModificationTime';
AApptCompareFieldValue := InvokePropertyGet(AOutlookAppointmentItem,
OutlookPropertyName);
Showmessage(AApptCompareFieldValue);
end;
 
S

Sue Mosher [MVP]

ItemProperties was added in a version after Outlook 2000. I don't remember
which. Please give your Outlook version whenever you post a new issue here;
it's almost always relevant.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


MB34 said:
Or use Item.ItemProperties.Item("property name") for simple, non-object
properties.

Thanks, Michael and Sue...

The Delphi Outlook object model does not expose the ItemProperties
either.

In the included Outlook2000.pas file, ItemProperties is not exposed so
I am able to get
it by using the code below instead of either modifying the
Outlook2000.pas file or importing
the Outlook TLB on my system.

const
EmptyDispParams: TDispParams = (rgvarg: nil; rgdispidNamedArgs: nil;
cArgs: 0; cNamedArgs: 0);

var
intLCID: Integer;

function GetDispId(const Obj: IDispatch; const Member: WideString;
DispIdPtr: PInteger): Boolean;
begin
Result := Succeeded(Obj.GetIdsOfNames(GUID_NULL, @member, 1,
intLCID, 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,
intLCID,
DISPATCH_PROPERTYGET,
DispParams,
@Result,
nil,
@ArgErr));
end;
end;


// Usage:

var
AApptCompareFieldValue: Variant;
OutlookPropertyName: WideString;
begin
intLCID := LOCALE_USER_DEFAULT;
OutlookPropertyName := 'LastModificationTime';
AApptCompareFieldValue := InvokePropertyGet(AOutlookAppointmentItem,
OutlookPropertyName);
Showmessage(AApptCompareFieldValue);
end;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top