Page 2 of 2
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 3:19 pm
by Enrico Maria Giordano
Yes, that's the module I'm experimenting with.
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 5:50 pm
by vensanto
__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.
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 5:53 pm
by Enrico Maria Giordano
Thank you, but I need it for xHarbour (please read the whole thread).
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 6:08 pm
by vensanto
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();
}
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 6:14 pm
by Enrico Maria Giordano
Thank you but, please, read the whole thread. We have already discussed that code.
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 11:47 pm
by James Bott
Enrico,
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
James
Re: How to create a PRIVATE variable owned by the caller?
Posted: Thu Jan 12, 2023 8:07 am
by Enrico Maria Giordano
I was sure you would write this.
I need it for back compatibility.