Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newobject in prg class does not use the second parameter
Message
From
10/10/2006 12:49:18
 
 
To
10/10/2006 04:28:24
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01160768
Message ID:
01160914
Views:
7
>Hi, We launched this already on the buglist, but since there's still not a singel reaction, we cannot but wonder how nobody else experiences this problem.
>Here goes :
>
>If you create a newobject() in a prg class in a method
>which calls a class with the same name but in another prg, the original class is instantiated again.
>Steps to reproduce
>
>Make a first prg called Vfp9Obj1.fxp
>
>LOCAL loTryThis
>loTryThis = NEWOBJECT("Bobtest","Vfp9Obj1.fxp")
>SET STEP ON
>loTryThis.DoSomething()
>
>DEFINE CLASS Bobtest as session
>
>	procedure Init
>	ENDPROC
>	
>	PROCEDURE DoSomething()
>		LOCAL loTest
>		loTest = NEWOBJECT("BobTest","Vfp9Obj2.fxp")	&&& Other prg file !!!
>		loTest.DoSomething()
>	ENDPROC
>ENDDEFINE
>
>
>Make the second class in fxp called Vfp9Obj2.fxp
>
>
>DEFINE CLASS Bobtest as session
>
>	procedure Init
>	ENDPROC
>	
>	PROCEDURE DoSomething()
>		WAIT WINDOW "test"
>	ENDPROC
>ENDDEFINE
>
>
>Observed results
>
>If you RUN the first prg, and step into the loTest.DoSomething(),
>you are redirected to the same DoSomething method instead of the new class
>
>Expected results
>
>The NewObject should use the Fxp parameter to instantiate the correct class

vfp OOP dones't support same classname into two different namespaces,
because the resource class manager is incomplete.
if you use NEWOBJECT with a class not present into the prg, it works,
but GETPEM BECOMES NOT DETERMINISTIC.
if it work into vfp8, then VFPT implement a partial bug fix into vfp9.

changes your oop model.
CLEAR CLASS  basebob
CLEAR

SET TEXTMERGE TO "namespace1.prg" OFF noshow
\DEFINE CLASS Bobtest as basebob
\
\ Procedure COMPUTE(A,B)
\   RETURN basebob::COMPUTE(A,B)
\
\ENDDEFINE

\DEFINE CLASS basebob as session
\	namespace = "namespace1"
\
\ Procedure COMPUTE(A,B)
\   RETURN a+b
\
\ENDDEFINE
SET TEXTMERGE TO 

COMPILE "namespace1.prg"

SET TEXTMERGE TO "namespace2.prg" OFF noshow
\DEFINE CLASS Bobtest as basebob
\
\ Procedure COMPUTE(A,B)
\   RETURN basebob::COMPUTE(A,B)
\
\ENDDEFINE

\DEFINE CLASS basebob as session
\	namespace = "namespace2"
\
\ Procedure COMPUTE(A,B)
\   RETURN a-b
\
\ENDDEFINE
SET TEXTMERGE TO 

COMPILE "namespace2.prg"

WITH  NEWOBJECT("BobTest","namespace1.fxp")
	? .namespace,GETPEM(.Class,"namespace"), .COMPUTE(1,1)
ENDWITH
?

WITH  NEWOBJECT("BobTest","namespace2.fxp")
	? .namespace,GETPEM(.Class,"namespace"), .COMPUTE(1,1)
ENDWITH
?

WITH  NEWOBJECT("BobTest","namespace1.fxp")
	? .namespace,GETPEM(.Class,"namespace"), .COMPUTE(1,1)
ENDWITH
Previous
Reply
Map
View

Click here to load this message in the networking platform