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

TOPIC:

GetFont() function 14 May 2022 18:15 #22466

  • Karl-Heinz
  • Karl-Heinz's Avatar
  • Topic Author


  • Posts: 774
  • Hi Devteam,

    is it allowed ;-) to use reflection to implement a x# runtime function ? I ask because i currently try to implement the VFP GetFont() function. Unfortunately, the Setoption() method of the .net FontDialog class is an internal method, but fortunately this method is accessible via reflection. I´m using this method to disable the script combobox and to enable the font description.

    Here´s a snippet how my code currently looks like:
    oDlg := FontDialog{} 
    	
    	oMi := TypeOf(FontDialog):GetMethod("SetOption", BindingFlags.NonPublic | BindingFlags.Instance)  
    
    	IF oMi != NULL 
    		   
    		// this enables the font description that is always shown in the left/bottom area of the VFP GetFont() dialog
    		oMI:Invoke(oDlg, { CF_PRINTERFONTS, TRUE }) 
    		
    		// btw. Its possible to include fonts like Courier, FixedSys, Terminal
    		// But since the .net FontDialog supports true type fonts only, trying to select e.g. FixedSys
    		// would trigger the .net runtime error "only true type fonts are supported"!		       
    		//
    		// oMI:Invoke(oDlg, { 0x00040000L , FALSE  }) // CF_TTONLY 
    		
        ENDIF 
    
     	oDlg:ShowEffects := FALSE 
    	oDlg:ShowHelp := TRUE
    	oDlg:MinSize := 4
    	oDlg:MaxSize := 127
    
    	
    	lReturnCharSet := IIF ( IsNil ( nFontCharSet ) , FALSE , TRUE ) 
    	
    	IF oMi != NULL .and. ! lReturnCharSet 		
    		// this disables the script combobox 
    		oMI:Invoke(oDlg, { CF_NOSCRIPTSEL, TRUE })		
    	ENDIF  
    What do you think ?

    regards
    Karl-Heinz

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

    GetFont() function 14 May 2022 19:44 #22467

    • robert
    • robert's Avatar


  • Posts: 3213
  • Karl Heinz,

    Using reflection is perfectly fine, as long as you add a check to make sure that the method indeed exists (like you are doing in your code above)
    In this case (of the FontDialog) it is very unfortunate that they have made the method internal. I see no reason to do that at all.
    In theory you could subclass FontDialog and try to do it from there, but the options field is private (not protected) and the SetOptions is internal.

    Robert




    Robert
    XSharp Development Team
    The Netherlands

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

    GetFont() function 14 May 2022 22:42 #22469

    • Chris
    • Chris's Avatar


  • Posts: 3667
  • Guys,

    Problem is though that AFAIK, admins can configure security settings in such way that such reflection "cheats" will cause runtime exceptions.
    So if possible I think it's better to avoid this. But if there's absolutely no other way...
    XSharp Development Team
    chris(at)xsharp.eu

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

    GetFont() function 15 May 2022 21:35 #22471

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • Guys,

    I think for now it would be useful if the Foxpro guys take a look at the current GetFont() implementation (see the attached viaef) and report if GetFont() works as expected.

    regards
    Karl-Heinz

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

    GetFont() function 18 May 2022 17:15 #22530

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • Hi Robert and Chris,

    i´ve noticed that i posted the "GetFont() function" topic to the private Fox forum. Is it possible to move the thread to the public Fox forum ?

    regards
    Karl-Heinz

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

    GetFont() function 18 May 2022 17:42 #22532

    • robert
    • robert's Avatar


  • Posts: 3213
  • Karl-Heinz,
    Yes, I'll do that.
    Btw: I did not include the function in the beta of 2.12.
    Will do that for the final release of 2.12.

    Robert
    XSharp Development Team
    The Netherlands

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

    • Page:
    • 1