RE: Converting a string to a variable name

new topic     » goto parent     » topic index » view thread      » older message » newer message

> It wasn't me who asked for a way to make var names *recently*, i have a 
> workaround, which i posted here. But i still say it should be in native 
> Euphoria.
> 
> Kat

Yeah I know Kat... there are probably 10 different ways to implement 
this.  It >would< be nice if this was native Euphoria, and it would also 
be nice if Euphoria would at least handle structures like all the other 
languages I have seen.  Sequences are nice, but not when working with 
the API.  Oh well, heres a couple of routines you can use to emulate 
dynamic variables through strings.

Note: The HashWin (window) I created is technically not needed.  The 
routines will attach a string variable to any window.  I placed it in 
the code to simplify the calling procedures/ functions.

===============

include Win32Lib.ew

constant
setProp = registerw32Procedure( user32, "SetPropA", 
{C_POINTER,C_POINTER,C_LONG} ),
getProp = registerw32Function( user32, "GetPropA", 
{C_POINTER,C_POINTER}, C_LONG ),
removeProp = registerw32Procedure( user32, "removePropA", 
{C_POINTER,C_POINTER} )

constant
HashWin = create( Window, "", NULL, 0, 0, 1, 1, {0} ),
hWndHash = getHandle( HashWin )

procedure SetStrVar( sequence StrVar, atom Value )
	atom hStrVar
	hStrVar = allocate_string( StrVar )
	w32Proc( setProp, {hWndHash,hStrVar,Value} )
	free( hStrVar )
end procedure

function GetStrVar( sequence StrVar )
	atom hStrVar
	atom RetVal
	hStrVar = allocate_string( StrVar )
	RetVal = w32Func( getProp, {hWndHash,hStrVar} )
	free( hStrVar )
	return( RetVal )
end function

procedure RemoveVar( sequence StrVar )
	atom hStrVar
	hStrVar = allocate_string( StrVar )
	w32Proc( removeProp, {hWndHash,hStrVar} )
	free( hStrVar )
end procedure

-- usage
--
-- to set: SetStrVar( "VarName", Value )
-- to get: GetStrVar( "VarName" )
-- (optional)to remove: RemoveVar( "VarName" )
--

===============

Don Phillips

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu