fbpx
Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

Set() function 30 Jul 2020 00:25 #15373

  • Karl-Heinz's Avatar

  • Karl-Heinz

  • Topic Author


  • Posts: 585
  • 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
    ...
     ...
     MEMBER Compare := 888   
     ...
     ...
     MEMBER Compatible := 666  
     ...
     ...
    and i want to know the "Compatible" setting.
    ? Set ( "comp" )
    When comparing with "Comp" or "Compa" always "Compare" and never "Compatible" is found. So
    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

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

    Set() function 30 Jul 2020 20:04 #15403

  • Karl-Heinz's Avatar

  • Karl-Heinz

  • Topic Author


  • Posts: 585
  • ok, Guys

    here´s what i tried. If you have any ideas on how to get a full name, add it to __GetFullName ()
    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 

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

    Set() function 31 Jul 2020 08:37 #15404

  • robert's Avatar

  • robert


  • Posts: 1793
  • Karl Heinz,
    I think the easier and faster solution is something like this:
    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

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

    Last edit: by robert.
    • Page:
    • 1