Thanks Erik that worked.
However sitting on Mts on another machine, the textboxes that are bound to this object refresh slowly. I believe it is because it needs to cross the network for each textbox data.
Michael
>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
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only