Set() function

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Set() function

Post by Karl-Heinz »

Hi DevTeam & Antonio

According the VFP help:

- All Set() string identifiers are reserved words, so they can be abbreviated to 4 chars.
- It´s not possible to change a setting with the Set() function. This must be done with the SET commands.
- some settings require a additional - position - param
? Set ("Device") -> <STRING> SCREEN, PRINTER, or FILE
? Set ("Device" , 1 ) -> <STRING> cFileName
or
? Set ("Device" , "1" ) -> <STRING> cFileName
- logical return values are displayed as "ON"/"OFF"

My first idea to scan the array returned by enum.GetNames( TypeOf (XSharp.Set)) to detect the full name of a abbreviated word is not a good idea, because XSharp.Set contains the identifiers of all dialects. Let´s say, XSharp.Set contains these identifiers

Code: Select all

 ...
 ...
 MEMBER Compare := 888   
 ...
 ...
 MEMBER Compatible := 666  
 ...
 ...
and i want to know the "Compatible" setting.

Code: Select all

? Set ( "comp" )
When comparing with "Comp" or "Compa" always "Compare" and never "Compatible" is found. So

Code: Select all

LOCAL nSetting AS XSharp.Set

IF Enum.TryParse( cFullIdentifierName , TRUE, OUT nSetting )
		
  uRet := XSharp.RT.Functions.Set(nSetting) 

ENDIF


would return the value of the wrong setting. Any ideas how to find the full name of a abbreviated word ? Sure, i could create my own scan list, but i prefer a cleaner solution ?

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Set() function

Post by Karl-Heinz »

ok, Guys

here´s what i tried. If you have any ideas on how to get a full name, add it to __GetFullName ()

Code: Select all

FUNCTION Start() AS VOID 
LOCAL cPath, cDBF AS STRING	


set century off
set exclusive off 

	
? Set ( "Winc" ) , Set ( XSharp.Set.WinCodepage ) 
?
? Set ( "eof" ) , Set ( XSharp.Set.EoF )  
?  
? Set ( "bell" ) , Set ( XSharp.Set.Bell ) 
?
? Set ( "Delimit" ) , Set ( XSharp.Set.Delimiters )
?         
? Set ( "Exclu" )  , Set ( XSharp.Set.Exclusive ) 
?
? Set ( "CenTur" ) , Set ( XSharp.Set.Century )
?
?
? 
set century on
set exclusive on
    
? Set ( "EXclu" ) , Set ( XSharp.Set.Exclusive )  	 
?
? Set ( "CenT" ) , Set ( XSharp.Set.Century )
?
?

RETURN

// Overrides the Set() function

FUNCTION Set( nDefine , newValue  ) AS USUAL CLIPPER 
LOCAL nSetting AS XSharp.Set
LOCAL cIdentifier AS STRING 
LOCAL uRet AS USUAL 
		
	 
	IF IsString ( nDefine ) 
		
		cIdentifier := ((STRING) nDefine).Trim().ToUpper() 	
		
		IF cIdentifier.Length > 3
			
 			cIdentifier := __GetFullName ( cIdentifier ) 
			
		ENDIF
		
		  	      
		IF IsNumeric ( newValue )  
		    
			/*
        	 a string identifier like 
			 Set ( "Device" , 1 ) 
			 becomes "Device1" 
			*/
			
			IF newValue > 0 
				cIdentifier += ((INT) newValue ).ToString() 
			ENDIF 	
			
		ENDIF 
		
? "Fullname: " , cIdentifier
		 
 		// If the name exists in the XSharp.Set enumeration 
		// <nSetting> is filled with the corresponding enum value

		IF Enum.TryParse( cIdentifier , TRUE, OUT nSetting )
		
			uRet := XSharp.RT.Functions.Set(nSetting)
		
			IF IsLogic ( uRet ) 
				uRet := IIF ( uRet , "ON" , "OFF" )
			ENDIF 				
			
			RETURN uRet  

		ENDIF
		
		THROW ArgumentException{} 
	
	ENDIF 	
	

	IF PCount() == 1 
		RETURN XSharp.RT.Functions.Set( nDefine )
	ELSE 	
		RETURN XSharp.RT.Functions.Set( nDefine , newValue)
	ENDIF


FUNCTION __GetFullName ( cIdentifier AS STRING ) AS STRING
	 
	VAR allNames := enum.GetNames ( TypeOf (XSharp.Set ) )  
	
 
	FOREACH VAR c IN allNames

		IF cIdentifier == c.Substring(0, System.Math.Min(cIdentifier.Length, c.Length) ).ToUpper()  
					       
			cIdentifier := c 
		
			EXIT 
					
		ENDIF 						         
			
	NEXT	
	
    RETURN cIdentifier 
User avatar
robert
Posts: 4555
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Set() function

Post by robert »

Karl Heinz,
I think the easier and faster solution is something like this:

Code: Select all

FUNCTION _GetSetId(cSetName as STRING) AS LONG
SWITCH Left(Lower(cSetName),4)
CASE "alte"
    RETURN Set.AlterNate
CASE "ansi"
   RETURN Set.Ansi
.
.
CASE "uniq"
   RETURN Set.Unique
END SWITCH
RETURN -1
And Maybe add the second parameter that is needed to differentiate between ALTERNATE and ALTERNATE,1
And can you let me know which of the FoxPro SET values we are still missing ?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply