This illustrates the problems that are caused by SCATTER NAME not being able to work with an existing object. Ok, now that Steve has pointed out that this isn't the case with a DLL, this topic doesn't serve its original purpose as well. Think of it as an example of how to return a SCATTER NAME object from a middle-tier business object.
OTOH, if the client side object wasn't created as a SCATTER NAME object, passing it to a middle tier object to get data using SCATTER NAME would cause it to lose its methods and any properties that aren't related to fields.
Did you try my scatter function that is in the Improving Scatter Name topic? It lets you scatter to a specified object.
No, the point is improving the SCATTER NAME command and providing justification for it to work with an existing object. There are lots of work arounds for this, just not anything native. I think the empty object is ultimately what's most important though, but I want both. -- Mike Feltman
Comment: two points about the code below:
- The crash you see does not depend on
SCATTER NAME. The
VFPCustomerServer.Customer.GET() can return an object of any class and you'll still get the exception.
Understood, but if SCATTER could work with an existing object, then the problem would not exist on objects created with SCATTER NAME. -- Mike Feltman
- The crash occurs only if you compile
VFPCustomerServer as a Win32 executible / COM server (exe) which is an Out - Of - Process Component. If you compile it as a Single-threaded or Multi-threaded COM server (dll), which is an In - Process Component, it works for me.
Make your factories In - Process Components. Factory classes should not be Out - Of - Process Components since the objects created cannot cross process boundaries. This makes some intuitive sense when you think about it.
-- Steven Black
Low and behold. You are absolutely correct. I didn't know this and apparently, Calvin didn't either or I didn't explain it to him properly. I'd still love SCATTER NAME to work on an existing object for other reasons, but this is great news to me! - Mike Feltman
Assume you have a client with the following code:
* Create a dummy cursor
CREATE CURSOR DUMMY (cCustomer_Id C(6))
* Create a SCATTER NAME object
SCATTER NAME oData
* Store a primary key value to the iPK property
oData.cCustomer_Id = "F1TECH"
* Create a business object via COM.
oBizObj = CreateObject("VFPCustomerServer.Customer")
*!* oBizObj = NewObject("Customer","VFPCustomerServer.PRG")
* Get the requested data from the business object
oData = oBizObj.Get(oData)
* Print the company name
* Release the business object
* Now try to print the company name
Now assume that
VFPCustomerServer.Customer is an ActiveX Server with the following class definition
DEFINE CLASS Customer AS Relation OLEPUBLIC
SELECT * FROM d:\vfe6\sample\data\Customer WHERE cCustomer_Id = oObject.cCustomer_Id INTO Cursor Temp
IF _TALLY > 0
SCATTER NAME oObject MEMO
cPK = oObject.cCustomer_Id
SCATTER NAME oObject MEMO BLANK
oObject.cCustomer_Id = cPK
If you run a test like this, the first attempt to print the company name will work fine. The second one will throw an exception because the object that now owns oData, the SCATTER NAME object, is out of scope because oBizObj has been released.
Category VFP Commands Category Code Samples
( Topic last updated: 2000.03.24 02:28:49 PM )