How to create a PRIVATE variable owned by the caller?


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

Postby vensanto » Wed Jan 11, 2023 5:50 pm

__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

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

Postby Enrico Maria Giordano » Wed Jan 11, 2023 5:53 pm

Thank you, but I need it for xHarbour (please read the whole thread).
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby vensanto » Wed Jan 11, 2023 6:08 pm

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

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

Postby Enrico Maria Giordano » Wed Jan 11, 2023 6:14 pm

Thank you but, please, read the whole thread. We have already discussed that code.
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby James Bott » Wed Jan 11, 2023 11:47 pm

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 view
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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

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

Postby Enrico Maria Giordano » Thu Jan 12, 2023 8:07 am

I was sure you would write this. :-) I need it for back compatibility.
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests

cron