Wednesday, September 26, 2012

Fixing Another Report Designer Issue

A couple of years ago, I blogged about a bug in FRXFormatUtil.ChooseFont. I ran into another issue in that method (not really a bug) recently. If you try to select a font for an object in the Report Designer and don’t have a default printer set up (as is sometimes the case in a Terminal Services environment), you get a “printer not ready” error. It turns out the reason is the use of the “P” switch in the GETFONT() function, which tells the Font dialog to only display fonts for the current printer. That errors out if you don’t have one.

I wrapped the GETFONT() calls in TRY blocks with a retry in the CATCH without the “P” flag. Here’s the updated code:

if THIS.FontCharSet = 0
*** DH 09/26/2012: wrap calls to GETFONT() with "P" switch in TRY and
*** if it fails, retry without that switch to avoid a "printer not ready"
*** error if there's no default printer
    try
        cFontString = getfont( ;
            THIS.FontFace, ;
            THIS.FontSize, ;
            THIS.StyleFlagsToChar( THIS.FontStyle)+"P", ;
            -1 )
    catch
        cFontString = getfont( ;
            THIS.FontFace, ;
            THIS.FontSize, ;
            THIS.StyleFlagsToChar( THIS.FontStyle), ;
            -1 )
    endtry
else
    try
        cFontString = getfont( ;
            THIS.FontFace, ;
            THIS.FontSize, ;
            THIS.StyleFlagsToChar( THIS.FontStyle)+"P", ;
            THIS.FontCharSet )
    catch
        cFontString = getfont( ;
            THIS.FontFace, ;
            THIS.FontSize, ;
            THIS.StyleFlagsToChar( THIS.FontStyle), ;
            THIS.FontCharSet )
    endtry
endif

(Yes, I realize this could be written more efficiently, but I wanted to make the minimum necessary changes to the code.)

No comments: