How to create a PRIVATE variable owned by the caller?
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: How to create a PRIVATE variable owned by the caller?
Yes, that's the module I'm experimenting with.
Re: How to create a PRIVATE variable owned by the caller?
__mvSetBase()
This is a hacking function which changes base private offset so PRIVATE variables created in function which calls __mvSetBase()
will not be released when the function exit but will be inherited by its caller.
Function sa_1()
sa_2()
? cTXT
Return .T.
Function sa_2()
Private cTXT:="CIAO"
__mvSetBase() // importante
Return .T.
This is a hacking function which changes base private offset so PRIVATE variables created in function which calls __mvSetBase()
will not be released when the function exit but will be inherited by its caller.
Function sa_1()
sa_2()
? cTXT
Return .T.
Function sa_2()
Private cTXT:="CIAO"
__mvSetBase() // importante
Return .T.
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: How to create a PRIVATE variable owned by the caller?
Thank you, but I need it for xHarbour (please read the whole thread).
Re: How to create a PRIVATE variable owned by the caller?
this is the function code in "memvars.c" of Harbour
HB_FUNC( __MVSETBASE )
{
HB_STACK_TLS_PRELOAD
HB_ISIZ nOffset = hb_stackBaseProcOffset( 0 );
if( nOffset > 0 )
hb_stackItem( nOffset )->item.asSymbol.stackstate->nPrivateBase =
hb_memvarGetPrivatesBase();
}
HB_FUNC( __MVSETBASE )
{
HB_STACK_TLS_PRELOAD
HB_ISIZ nOffset = hb_stackBaseProcOffset( 0 );
if( nOffset > 0 )
hb_stackItem( nOffset )->item.asSymbol.stackstate->nPrivateBase =
hb_memvarGetPrivatesBase();
}
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: How to create a PRIVATE variable owned by the caller?
Thank you but, please, read the whole thread. We have already discussed that code.
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: How to create a PRIVATE variable owned by the caller?
Enrico,
Why are you using a PRIVATE? I haven't used PRIVATEs for years.
You can do the same thing you wanted this way:
James
Why are you using a PRIVATE? I haven't used PRIVATEs for years.
You can do the same thing you wanted this way:
Code: Select all | Expand
FUNCTION MAIN()
LOCALE cName:=""
cName:= CREATEVAR( cName, "Hello" )
? cName // it exists here
RETURN NIL
STATIC FUNCTION CREATEVAR( cName, xValue )
cName:= xValue
RETURN xValue
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: How to create a PRIVATE variable owned by the caller?
I was sure you would write this. I need it for back compatibility.