How to create a PRIVATE variable owned by the caller?

User avatar
vensanto
Posts: 58
Joined: Thu Oct 13, 2005 1:26 pm
Location: ITALIA
Contact:

Re: How to create a PRIVATE variable owned by the caller?

Post 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.
User avatar
vensanto
Posts: 58
Joined: Thu Oct 13, 2005 1:26 pm
Location: ITALIA
Contact:

Re: How to create a PRIVATE variable owned by the caller?

Post 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();
}
User avatar
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?

Post by Enrico Maria Giordano »

Thank you but, please, read the whole thread. We have already discussed that code.
User avatar
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?

Post 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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Post Reply