Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AddProperty and Com.dll
Message
From
01/11/1998 03:59:20
Eric Barnett
Barnett Solutions Group, Inc
Sonoma, California, United States
 
 
To
31/10/1998 17:04:04
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00152924
Message ID:
00153230
Views:
27
I know what you are trying to get at: being able to have named properties for a middle-tier object, a la Customer.Name. I tried to do the same thing when I first started playing with COM and AddProperty, but unfortunately it doesn't work. Here's why:

When you create your COM object, the calling object gets the available interfaces for the object at instantiation. This lets the calling object know about what methods and properties (well, actually all methods, but I'm not going to get in to that) exist, and what the parameter and return types are so variables can be cast back and forth from the calling program and the COM object. Unfortunately, when you call AddProperty, although VFP knows about the additional property the property does not exist as part of the interface over COM since the available properties and methods are not rediscovered (introspected). Therefore you get the error, Unknown Name.

The workaround for this is to add an object to your class. Then use AddProperty to add properties to that object. I usually use a getobject() type function to return values myself. Here's a simple example:

DEFINE CLASS datacomobject AS OLEPUBLIC
oDataObject=.NULL.
FUNCTION oDataObject_Access
IF VARTYPE("this.oDataObject")#"O"
this.oDataObject=CREATEOBJECT("Custom")
ENDIF
ENDFUNC
FUNCTION loaddata
this.oDataObject.addproperty("Data1","Value1")
this.oDataObject.addproperty("Data2","Value2")
(etc...whatever you need to expose)
ENDFUNC
FUNCTION getdataobject
RETURN this.oDataObject
ENDFUNC
ENDDEFINE

Although you don't really need that getdataobject: oDataObject will be exposed since it exists as part of the defined interface for datacomobject.

Hope this helps.

>Thanks for your help.
>
>
>The propblem occurs when a method of the class uses the addproperty() method. as follows
>x = createobject("comprop.testaddprop")
>x.addprop()
>
> Addprop Method
> this.addproperty("test1", "test1")
>
>? x.test1
>Error Unknown Name.
>
>
>This error only occurs when the component is a com.dll. When I use the set classlib to ... and
>x = createobject("testaddprop")
>the above code works.
>
>
>I could not get your solution to work. There was a property that existed in my class when I compiled it. I ran the following code:
>
>x = createobject("comprop.testaddprop")
>x.test7 = "test7"
>? x.test7
>Returned test7
>
>? x.returnprop(test7)
>Error varialbe test7 not found
>
>? x.returnprop('test7')
>Error Unknown Name
>
>
>
>
>>I had a lot of trouble with this same sort of thing -- sharing the data component of a COM object. After several months (literally) talking to the MS help lines I learned the secret. It seems that you must expose a method in the COM object to return any of the data properties. Instead of:
>>
>>de = createobject('databridge.de')
>>? de.propname
>>
>>you need to:
>>
>>de = createobject('databridge.de')
>>? de.returnprop(propname)
>>
>>I hope this helps.
>>
>>Rick Grinter
Eric Shaneson
Cutting Edge Consulting
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform