GetFont() 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

GetFont() function

Post by Karl-Heinz »

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:

Code: Select all

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
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

GetFont() function

Post by robert »

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
robert@xsharp.eu
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

GetFont() function

Post by Chris »

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...
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

GetFont() function

Post by Karl-Heinz »

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
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

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

GetFont() function

Post by Karl-Heinz »

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
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

GetFont() function

Post by robert »

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
robert@xsharp.eu
Post Reply