FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to create a PRIVATE variable owned by the caller?
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 03:19 PM

Yes, that's the module I'm experimenting with.

Posts: 58
Joined: Thu Oct 13, 2005 01:26 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 05: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.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 05:53 PM

Thank you, but I need it for xHarbour (please read the whole thread).

Posts: 58
Joined: Thu Oct 13, 2005 01:26 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 06: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();

}

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: Wed Jan 11, 2023 06:14 PM

Thank you but, please, read the whole thread. We have already discussed that code.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: 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 (fw): Select all Collapse
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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to create a PRIVATE variable owned by the caller?
Posted: Thu Jan 12, 2023 08:07 AM
I was sure you would write this. :-) I need it for back compatibility.

Continue the discussion