Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

private variable pased by ref to a method 10 Mar 2021 16:21 #17725

  • jpmoschi
  • jpmoschi's Avatar
  • Topic Author


  • Posts: 76
  • Good morning forum, look this case
    When a private variable not change by ref values inside a method but if i change the private declaration with local the problem is resolved. Remember i am testing in 2.6a

    private loteprueba
    loteprueba:= 10
    obj:ArrobaGet(1 , 0+ len("Test Loops:") , @loteprueba, "99999999")
    // loteprueba never changed !!!! But inside ArrobaGet i am sure, value is changed!!!

    Thanks
    Juan

    Please Log in or Create an account to join the conversation.

    private variable pased by ref to a method 10 Mar 2021 17:56 #17728

    • robert
    • robert's Avatar


  • Posts: 3446
  • Juan,

    Is obj typed ?
    In other words: is this what we call an "early bound" method call or a "late bound" method call ?

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    private variable pased by ref to a method 11 Mar 2021 10:40 #17744

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Robert,

    i compiled with 2.7 an older sample that uses the Fox dialect and noticed that the caller doesn´t see a changed ref value if the Fox "=" assignment is used . The only way to make it work is to use inside the ref function/method the ":=" assignment.

    The only compiler switch i´m using is the /memvar option. I also tryied /lb, but that doesn´t change the ref behaviour of the method call. Looking with ILSpy at the code shows that the ref related "=" code is different than the ":=" code.
    FUNCTION TestByRef( ) AS VOID
    LOCAL x2 AS STRING
    LOCAL o AS Foo 	
    
    // LOCAL x AS STRING 
    LOCAL x 
    // PRIVATE x 
    
    
    x = "old"
    ? x
    o = Foo{}
    o:TestUntyped(@x )
    ? "(Method) must be 'new': " , x 
    ?  
    
    x = "old"
    ? x
    TestUnTyped ( @x ) 
    ? "(Function) must be 'new': " , x            
    ? 
    
    x = "old" 
    ? x  
    TestUnTyped ( x )
    ? "(Function) must still be 'old': " , x 
    ? 
    
    x = "old"
    ? x
    DO TestUnTyped WITH x 
    ? "(Procedure) must be 'new': " , x 	 
    ? 
    
    x = "old"
    ? x
    DO TestUnTyped WITH (x) 
    ? "(Procedure) must still be 'old': " , x
    ? 	
    
    x2 = "old"
    ? x2
    TestTyped ( @x2 )
    ? "(Typed Func) must be 'new': " , x2   
    ?
    RETURN 
    
    FUNCTION TestUnTyped ( x )
    // PARAMETERS x	
        
    	IF IsByRef ( x )
    		
    		// x := "new" // This works !
    		
    		// note: if the Fox "=" assignment is used 
    		// the caller doesn´t see the changes ?
    		 
    		x = "new"  
    		
    		
    		? "ByRef: change param value" 
    		
    	ENDIF 	
    	
    	RETURN  .t.
    	
    
    FUNCTION TestTyped ( c REF STRING ) AS LOGIC 
    	
    	c = "new"  // no problem with the Fox "=" assignment 
    	
    	RETURN TRUE
    	
    	
    CLASS Foo
    	
    
    METHOD TestUntyped ( x ) 
    	
    	IF IsByRef ( x )
    		
    		// x := "new" // This works !
    		
    		// note: if the Fox "=" assignment is used 
    		// the caller doesn´t see the changes ?
    		
    		x = "new"  
    		
    		? "ByRef: change param value" 
    		
    	ENDIF 
    	
    	RETURN
    	
    END METHOD 		
    
    END CLASS 		

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    private variable pased by ref to a method 11 Mar 2021 11:13 #17745

    • Chris
    • Chris's Avatar


  • Posts: 3843
  • Hi Karl-Heinz,

    I think you are testing with the newer compiler test release, not 2.7, because this seems to work fine in 2.7. But I can indeed reproduce the behavior in the new 2.8 compiler, the by ref param is assigned the new value back only when using the ;= operator, not with =. Will log a test for this, thanks for reporting it!
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    private variable pased by ref to a method 11 Mar 2021 11:44 #17746

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Chris,

    mmmhh ...

    no, i don´t use the 2.8 compiler. When i compile the posted sample the XIDE output shows version 2.7.0.0 ?

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.

    private variable pased by ref to a method 11 Mar 2021 12:00 #17747

    • Chris
    • Chris's Avatar


  • Posts: 3843
  • Hi Karl-Heinz,

    Hmm, that's strange, when I compile with 2.7 here, I get a compiler error for the FUNCTION TestTyped() declaration. If I remove this, then the code runs as expected, but only if /fox2+ is enabled (when it is disabled, I see that indeed the value is not updated).

    Anyway, it's not really important what happens with 2.7, I still see some issues in 2.8 so I have logged a sample now.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    private variable pased by ref to a method 11 Mar 2021 14:17 #17750

    • jpmoschi
    • jpmoschi's Avatar
    • Topic Author


  • Posts: 76
  • Hi Robert
    Obj is defined like this
    private Obj
    Obj:= MyStartupCode:WinFormOn()
    and WinFormOn() is a static method like this
    static method WindOmaOn() as WinForm_private // and this one inherit from System.Windows.Forms.Form

    Regards
    Juan

    Please Log in or Create an account to join the conversation.

    private variable pased by ref to a method 11 Mar 2021 17:11 #17756

    • robert
    • robert's Avatar


  • Posts: 3446
  • Juan,
    Ok, so obj is a private memory variable. That means that:
    - the call is late bound
    - we cannot really pass the address of the variable. There is no location on the stack. So we must pass the value of the variable to the method and when the method returns we must assign the changed value back to the private variable.
    I thought we had this working, but apparently there is a problem when the assignment in the method is done with the '=' operator and not with the ':=' operator.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1