Font Setting

ankit_jkt

New Member
Hi All,

I want to fetch the updated font information without putting this information permanently into related font .ini file.

I am using the given code to allow user to update font setting:-

DEFINE VARIABLE iFont AS INTEGER NO-UNDO INITIAL 3.
DEFINE VARIABLE cChangeFont AS CHARACTER NO-UNDO.

SYSTEM-DIALOG FONT iFont. /* To open the font dialog and allow user to update font setting */

GET-KEY-VALUE SECTION "FONTS" KEY "Font" + STRING(iFont) VALUE cChangeFont. /* To store the updated font value in "cChangeFont" */


I am expecting variable "cChangeFont" is updated with new font setting but it is still giving me the old font setting.

If i update the font related file through "PUT-KEY-VALUE FONT iFont" and fetch the font setting again it returns me updated font setting. But i do not want to update this file ever.


Regards
Ankit Kumar
 
OP is trying to get font information without writing to the ini file.

I thought I would be able to redirect everything to a temp INI file, but PUT-KEY-VALUE is failing... which is confirmed as expected behavior by ProKB - the work around, assign ONE dummy font number - you will need write rights to the key / file which I think you are trying to avoid.

Code:
DEF VAR ctempini AS CHAR NO-UNDO.
DEF VAR cfonts AS CHAR NO-UNDO EXTENT 256.
DEF VAR ii AS INT NO-UNDO.
DEFINE VARIABLE iFont AS INTEGER NO-UNDO INITIAL 3.
DEFINE VARIABLE cChangeFont AS CHARACTER NO-UNDO.
DEF VAR lok AS LOGICAL.

ctempini = SUBSTITUTE( "&1&2.ini", SESSION:TEMP-DIRECTORY, GUID ).

/* get current values... */
DO ii = 0 TO 255:
   GET-KEY-VALUE SECTION "fonts" KEY SUBSTITUTE( "font&1", ii ) VALUE cfonts[ii + 1].
END.

LOAD ctempini DIR SESSION:TEMP-DIRECTORY NEW BASE-KEY "INI".
USE ctempini.

/* ... and write to temp ini - I thought that lack of values was causing PUT-KEY-VALUE FONT to fail */
DO ii = 0 TO 255:
   IF cfonts[ii + 1] > "" THEN
      PUT-KEY-VALUE SECTION "fonts" KEY SUBSTITUTE( "font&1", ii ) VALUE cfonts[ii + 1].
END.

SYSTEM-DIALOG FONT iFont UPDATE lok.
IF lok THEN DO:
   PUT-KEY-VALUE FONT ifont. /* <--- and here it fails - since fonts can only be written back to the default environment */
   GET-KEY-VALUE SECTION "fonts" KEY SUBSTITUTE( "font&1",iFont ) VALUE cChangeFont.
   MESSAGE cchangefont VIEW-AS ALERT-BOX.
END.

UNLOAD ctempini.
OS-DELETE VALUE( ctempini ).
 
Back
Top