fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: MEMVARs, PUBLICs etc.

MEMVARs, PUBLICs etc. 3 weeks 4 days ago #8825

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Guys,

a journey back to the roots :-)

I´m just playing with the PUBLIC/PRIVATE/MEMVAR feature. That´s what i´ve noticed so far:

1. If a PUBLIC is declared and no value is assigned, the initial value is NIL and not .f. It seems that it´s not possible to declare a PUBLIC within the Start().

2. It´s not possible do declare a PRIVATE and assign a value at the same time. Depening on the compiler setting either a warning or an error is thrown.

More comments and some tests are in the attached ZIP which contains a XIDE viaef and a dbf

NOTE: currently the path to the used DBF points to "D:\TEST"
The used compiler switches are "-memvar+ -undeclared+"

Any comments are welcome.

regards
Karl-Heinz
Attachments:

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 3 weeks 4 days ago #8827

  Chris's Avatar Chris Offline Posts: 1109
Hi Karl-Heinz,

Oh, I completely forgot to add support for those compiler options in the property pages, sorry about that, will do it ASAP. Thanks for your reports, indeed this feature has been tested very little, will log all the issues so they will be taken care of.
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 3 weeks 3 days ago #8841

  robert's Avatar robert Offline Posts: 946
Karl-Heinz,
Thanks for the report. Will check this out asap.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 3 weeks 3 days ago #8854

  Chris's Avatar Chris Offline Posts: 1109
Robert, I have added a cut down compiler test for that.
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 3 weeks 8 hours ago #8932

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Chris,

two notes.

1. In my sample there is the procedure
PROCEDURE ThisDoesNotCompile() 

#IFDEF __COMPILEERROR__	

  MEMVAR Amount, Address
  PRIVATE Amount := 100 

#ENDIF 

RETURN 

i´ve enabled the VO compatible preproccessor behavior and added

#DEFINE __COMPILEERROR__ := FALSE

but It seems the VO8 switch has no effect, because the #IFDEF code is not ignored. BTW. The compiler macro __VO8__ shows correctly .t. if the VO8 setting is enabled.


2. Typed/Untyped Start()

The app must use a typed Start() otherwise it doesn´t compile. Wouldn´t it make sense to allow a untyped Start() if the memvar "mode" is enabled ?


Regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 3 weeks 7 hours ago #8937

  Chris's Avatar Chris Offline Posts: 1109
Hi Karl-Heinz,

Remove the ":=" from your #define and it should work as expected. Remember, #define is a preprocessor directive (so no :=), while a DEFINE is "executable" code, so you do need the := with them.

About an untyped Start(), I think it's a requirement of the framework that the Start/Main function (the entry point) has one of few specific signatures, so we cannot allow everything. But Robert may correct me if i am wrong.
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 3 weeks 6 hours ago #8939

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Chris,

Yes,

#DEFINE __COMPILEERROR__ FALSE // or TRUE

behaves as expected.

Thanks !

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 4 days ago #8969

  robert's Avatar robert Offline Posts: 946
Karl Heinz,
I have looked at this and found the problem with the File Wide PUBLICs: they were parsed incorrectly as GLOBALs and not as PUBLICs. That is why they were initialized with NIL in stead of FALSE. (PUBLIC in X# is also an alias for EXPORT, and this caused the confusion). I have fixed that now.
Since there is no "Context" in which they can be initialized they will now be initialized in the same code where Init procedures are called at startup of the app. The file wide PUBLICs are now initialized after all INIT3 procedures have been called.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 3 days ago #8971

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Robert,

In the meantime i´ve found a "workaround" :-)to create PUBLICs

FUNCTION Start() AS VOID

 Example3()

 ? "Content of the Public gc4" , gc4

RETURN


PROCEDURE Example3()
// PUBLIC gc4 
 
    __MemVarDecl("gc4" , FALSE )
    ? "content of gc4: " , gc4  //  ok, shows FALSE
    gc4 := "I´m a public"  	
	
    RETURN 


regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 3 days ago #8972

  robert's Avatar robert Offline Posts: 946
Karl Heinz,
You found the right function.
This is fixed now in the compiler as well.
Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 2 days ago #8978

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Robert

i´ve looked at the _Mxxx() memvar funcs and it looks good. The only problem so far is the _MRelease() behaviour.

i had to change the line:

WHILE text != __Symbol{""}

to:

WHILE text != NULL

otherwise the DO .. WHILE is in a endless loop

FUNCTION Start( ) AS VOID 
PRIVATE x1, x2,x3 

	x1 := 1 
	x2 := 2
	x3 := 3 
	

	 ? "Number of PRIVATEs:" , memvar:PrivatesCount()   // 3 
	 ?
	 
     ? "private x1 content before _MRelease()" , x1    // 1
     ? "private x2 content before _MRelease()" , x2     // 2
     ? "private x3 content before _MRelease()" , x3	 // 3
	
// 	 _MRelease ( "x*" , FALSE )  // ok, doesn´t release any of the privates 
   	 _MRelease ( "x*" , TRUE )  // ok, does release x1, x2 and x3 
//	 _MRelease ( "x1" , FALSE )  // ok, does release x2 and x3 only  	    
//	 _MRelease ( "x1" , TRUE )  // ok, does release x1 only  		
     
	 ?
     ? "private x1 content after _MRelease()" , x1   
     ? "private x2 content after _MRelease()" , x2   
     ? "private x3 content after _MRelease()" , x3   	
     ?
	 ? "Number of PRIVATEs before _MClear():" , memvar:PrivatesCount()   // 3
	 
  	?  
   	_MCLEAR() // remove all privates and publics
   	?
  	? "Number of PRIVATEs after _MClear():" , memvar:PrivatesCount()  // 0  		
    ?	   
		
	RETURN

// overrides the Xsharp.RT  _MRelease()
FUNCTION _MRelease(cMask AS STRING , lMatch AS LOGIC ) AS VOID
	LOCAL text AS STRING
	//
	cMask := XSharp.Core.Functions.Upper(cMask)
	text := _PrivateFirst(FALSE)
	WHILE text != NULL // __Symbol{""} //  KHR changed to NULL 
		IF (XSharp.Core.Functions._Like(cMask, text) == lMatch)
			MemVarPut(text, __Usual._NIL)
		ENDIF
		text := _PrivateNext()
	END WHILE    

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 2 days ago #8979

  wriedmann's Avatar wriedmann Offline Posts: 1515
Hi Robert,

may I suggest to add functions without underscores and document them officially?
They are particularly interesting for macro evaluation, to inject variables into the macro compiler.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 2 days ago #8984

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Wolfgang,

There are 5 funcs:

_MRelease()
_MXReleaese()
_MSave()
_MRestore()
_MClear()

and none of them are documented in VO, so i´m sure the intention is not to use these funcs directly. In VO they are only used if a command like "SAVE ..." is included, that the preprocessor translates to "_MSave ( .... ). Of course almost none of the VOers use PRIVATES and PUBLICs anymore, but they are essential for e.g. Foxpro users.

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 2 days ago #8988

  wriedmann's Avatar wriedmann Offline Posts: 1515
Hi Karl-Heinz,

it would be interesting to have them documented and usable officially because they can help when pushing variables to the macrocompiler (this is the only case where I would need them).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 2 days ago #8989

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234

wriedmann wrote: Hi Karl-Heinz,

it would be interesting to have them documented


The functions are described in the XSharp runtime help.

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 2 days ago #8990

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Wolfgang

you can do funny things with the memvar internals :-)

__MemVarDecl("c" , TRUE ) // create a private
__MemVarPut ( "c" , 100 )
// Memvar:put( "c" ,100 )

__MemVarDecl("d" , TRUE ) // create another private
__MemVarPut ( "d" , "c" )
// Memvar:put( "d" ,"c" )

? &("d" ) // "c"
? & ( &("d" ) ) + 100 // 200

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 2 weeks 1 day ago #8991

  wriedmann's Avatar wriedmann Offline Posts: 1515
Hi Karl-Heinz,

you can do funny things with the memvar internals


I know!
Specially with macros or code blocks they are very powerful.

But also the .NET architects have seen the need for dynamic variables and added the Expando class, and dynamics.
But the VO/X# implementation IMHO is much more powerful.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 1 week 5 days ago #9004

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 234
Hi Robert,

I looked at the Foxpro RELEASE command.

-- Foxpro code ---

x = 12

RELEASE x

? x && Foxpro error "var 'x' not found" is thrown


While the VO/X# RELEASE doesn´t delete a var, the Foxpro RELEASE does. In the X# runtime there´s already the method memVar:ClearAll(), but what´s IMO missing is something like MemVar:Clear ( <cVar>), so the Foxpro RELEASE could be mapped to memVar:Clear ( "x" ).

what do you think ?

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

MEMVARs, PUBLICs etc. 1 week 5 days ago #9006

  robert's Avatar robert Offline Posts: 946
Karl-Heinz,

This shows exactly how tricky it can be to support more than one dialect.
The current implementation of RELEASE does what the VO docs say.

"This command does not actually delete the specified variables from memory like CLEAR ALL or CLEAR MEMORY. Instead, it releases the value of the variables by assigning NIL to them. For this reason, variables that are hidden do not become visible until termination of the routine initiating the RELEASE operation."

To solve this problem I see 2 solutions:
1) have a different header file for VO and FOX or different implementations in the same header file (using conditional compilation) that map the RELEASE command to different function calls
2) Detect the active dialect at runtime and change the behavior of the _MRelease() function depending on the active dialect.

When choosing 1) we could also introduce a new command (or a new clause ) for VO to allow also code in the VO Dialect to completely remove the variables.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1