fbpx

Override the chr() function

  • Karl-Heinz Rauscher
  • Karl-Heinz Rauscher's Avatar Topic Author
  • Offline
More
3 months 2 weeks ago #1 by Karl-Heinz Rauscher
Override the chr() function was created by Karl-Heinz Rauscher
i´m not able to override the chr() func, while overriding Asc() works as expected. Strange is, that if i place within XIDE the mouse over "chr(196)" the tooltip says "Defined" in my exe, but the compiler generates this code:

c := XSharp.Core.Functions.CHR(196u) // still pointing to the core function chr()

dw := Asc("Ž") // ok, points to the Asc() func in the created exe

Any ideas what the problem with "Chr" might be ?

_DLL FUNCTION MessageBox(hwnd AS intptr , lpText AS STRING, lpCaption AS STRING, uType AS DWORD);
	AS INT PASCAL:USER32.MessageBoxA ANSI

#define _OVERRIDE_ASC_AND_CHR_

#ifdef _OVERRIDE_ASC_AND_CHR_

FUNCTION CHR (dwChar AS DWORD ) AS STRING
 
	? "Chr() override" 

	RETURN XSharp.Core.Functions.ChrA ( dwChar )		
	
FUNCTION Asc (c AS STRING ) AS DWORD 

	? "Asc() override" 
		
	RETURN XSharp.Core.Functions.AscA(c )
	
#endif

FUNCTION Start() 	AS VOID 
LOCAL dw AS DWORD 
LOCAL c AS STRING 

	
	c := CHR( 196 )   // should show "Ä"
	
	dw := asc ( "Ž" )    // should show 142 
	
	
	messagebox ( NULL ,  c + chr(13) + chr(10) + ntrim ( dw ) , "" , 0 )  
	
	
RETURN  


regards
Karl-Heinz

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

More
3 months 2 weeks ago #2 by Robert van der Hulst
Replied by Robert van der Hulst on topic Override the chr() function
Karl-Heinz,

Chr is a special function in X# (and in Vulcan too): When the parameter is a literal number and its value is between 0 and 127 then the matching character literal is inserted in the code.
Otherwise a call to the XSharp.Core.Functions.Chr() is inserted.

We never expected that our users would want to replace the function.

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.