Accessing dynamic text's DateSaved Document property as text

406
4
12-06-2011 11:38 AM
MeToo
by
New Contributor
I need to programmatically access the text displayed by the dynamic text Document DateSaved property.

I believe ArcGIS gets this information using IDocumentInfo2.DateSaved. However, the latter returns an Object and not an ITimeInstant or ITime as I would have expected. Furthermore, there is no documentation on how to handle this "Object".

How does one turn the Object into the text string that ArcMap displays in dynamic text elements? I wasn't able to cast the returned Object to ITimeInstant or ITime, or to set it as a Date. The object seems to be a Double. I use VB.NET.

Thanks,
Dennis
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
The property returns an Object because not all languages have a Date data type and the ones that do vary in its implementation.  Dates can be converted to an equivalent double precision number, which is what the property does because all languages should have some implementation of a double precision data type.  In .NET you can use this to get the value:

Dim d As Date = Date.FromOADate(docInfo.DateSaved)
0 Kudos
MeToo
by
New Contributor
Thanks Neil for the method and explanation.

Once again, I think it should have been explained on the DateSaved page of the ArcMap help system...

Phil_M of Esri suggested another method that works too:

Dim theDateSaved As ESRI.ArcGIS.esriSystem.ITime = New ESRI.ArcGIS.esriSystem.Time
theDateSaved.SetFromObject(pDocumentInfo2.DateSaved)

Dennis
0 Kudos
MeToo
by
New Contributor
Neil:

I gave your explanation of why IDocumentInfo2.DateSaved returns an Object a little bit more thoughts and think it would make a lot of sense if that interface and member had been developed by Esri prior to ITime, but they were both released with ArcGIS 10.

Doesn't this mean that Esri could have returned ITime instead of Object as ITime seems to be available for all programming languages supported by ArcGIS? Why go the extra step?

Thanks,
Dennis
0 Kudos
NeilClemmons
Regular Contributor III
Handling dates as double precision values for cross-language/platform use is pretty standard.  My guess would be that they decided to keep it simple as opposed to wrapping the return value in even more COM overhead.  It's also just as likely that whoever designed the IDocumentInfo2 interface wasn't even aware of the ITime interface or that they didn't really think about it too much at all.  Only ESRI really knows why they implemented it this way.
0 Kudos