Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to create cursor from object (GATHER NAME on steroid
Message
De
05/03/2006 22:03:51
 
 
À
05/03/2006 11:39:52
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01101568
Message ID:
01101614
Vues:
24
Hi Dragan,

Looked at Microsoft Office Automation with Visual FoxPro. Outlook does not have the most helpful behavior. Thanks for your help.

Outlook behaves differently than Excel. For example, with your example as soon as you create the ox object, you can see properties in the watch window. For Outlook the only think you can see is "GetNamespace". It doesn't show pems with amembers either, but it does with intellisense. If you access any of the properties with the help of intellisense, or because you just knew the name, it then shows up with amembers. It's as if you are looking at a proxy object that only gets properties added as they are discovered some other way. Wonder how I can tell the object to find all underlying properties?

Alex


>>If you have an object created by some external application (in this case Outlook) and would like to create a table with all properties as fields, what is the most direct way?
>
>I don't see a direct way, for several reasons.
>
>First, because of VFP's late binding of COM objects, aMembers() most probably won't give you much... OOPsss, it does now in 9sp1. Here goes:
>
>
#Define hTab Chr(9)
>#Define hCR Chr(13)
>oEx=Createobject("excel.application")
>N=Amembers(a, oEx, 3)  && 3 gives you COM object PEMs
>
>cList=""
>cComma=" ("
>oEmpty=createobject("empty")
>For i=1 To N
>	If a[i,2]="PropertyGet"
>		cName=a[i,1]
>		Try
>			lOK=.T.
>			uvalue=Getpem(oEx,cName)
>		Catch
>			lOK=.F.
>		Endtry
>		If Not lOK
>			Loop
>		Endif
>		cType=Vartype(uvalue)
>		Do Case
>*-- skip object and null properties
>			Case cType$"OX"
>				lOK=.F.
>			Case 	cType="C"
>				nLen=Len(uvalue)
>				*-- scheck for null strings, and add space just in case
>				nLen=iif(nlen=0, 10, int(nLen*1.5))
>				cLen="("+Transform(nLen)+")"
>			Case cType$"NIFBY"
>*-- do a more precise one if needed... still, how to recognize integers?
>				cLen="(18,2)"
>			Case cType$"LDT"
>				cLen=""
>			Otherwise
>				cLen=""
>		Endcase
>		If Not lOK
>			Loop
>		Endif
>		addproperty(oEmpty, cName, uValue)
>		cList = cList + cComma+cName + hTab+ cType+" "+cLen
>		If i%3=2
>			cComma=","+hTab
>		Else
>			cComma=","+hTab+";"+hCR
>		Endif
>	Endif
>Endfor
>cList = cList + ")"
>*-- TEXT BLOCK BEGIN
>TEXT TO lcPrg NOSHOW TEXTMERGE
>lparameters oE
>create cursor crsFromExcel <<cList>>
>insert into crsFromExcel from name oE
>edit
>ENDTEXT
>*-- TEXT BLOCK END
>Strtofile(lcPrg, "cursorFromExcel.prg")
>execscript(lcPrg, oEmpty)
>
>
>Tried, works. At least for Excel.
>
>You see the flaws here - we don't know the exact lengths of the strings, we don't know the exact format of the numbers, we need to do a lot of more tweaking to guess which fields should actually be memos (I figure you want a typical Outlook object, which would contain at least one longish text field), many of the properties are null at the time you build the cursor (and so we don't know whether they'd be strings, objects or what once they're not).
>
>Another thing to beware of - what do you do if there are more than 255 eligible properties? That can easily happen with any rich enough DOM.
>
>Worst of all, you can't Insert Into YourCursor from oEx (or oOL in your case) because that simply doesn't work. Probably because the properties aren't just exposed as in VFP, they're PropertyGet methods, so you have to pull them one by one like I did here. So you'd need a loop like this to just add properties to an empty object, and insert from that.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform