>>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)
>
>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.
Ok, I may try to work from this idea.
Thanks.
UPDATE. Didn't work with GetPem for some reason, but worked with EVALUATE and I got
Address: && e-mail
Application: (Object)
Class: 8
DisplayType: 0
ID: 00000000C091ADD3519DCF11A4A900AA0047FAA4C200000000A65905F85A9ADF42B4559F0CAA9E02B004BF2300
Manager: .NULL.
Members: .NULL.
Name: Adrián Hernández
Parent: (Object)
Session: (Object)
Type: SMTP
If it's not broken, fix it until it is.
My Blog