FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problem with font
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Problem with font

Posted: Thu Jun 09, 2016 08:23 AM
On my application on Main.prg I use a Object class Tapplication (oApp) and set the DATA oFont with

::oFont := TFont():New( GetDefaultFontName2(), 0, GetDefaultFontHeight2(),, )


on all prgs I use the expression oApp():oFont to call this font
then when I close the application end the font with ::End()

Sometimes the exe while I use this application change the type of this font to Bold and I not understood why

for a sample :

BEFORE



AFTER

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem with font

Posted: Thu Jun 09, 2016 02:20 PM
Silvio,

I have seen this type of thing when resources are low.

on all prgs I use the expression oApp():oFont to call this font
then when I close the application end the font with ::End()


It appears that you are using the application font (oApp():oFont), then you are ending it. Then next time you are trying to use the same font that you just ended.

Try creating a clone of the app font

oFont:= oClone( oApp():oFont )

Then ending the clone when you are done with it.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 03:22 AM
Hello,

I have a similar problem, I thought using global variable to define font and use it in diferent places would be a good approach. I use a global font definition in many places of my app, I use no modal dialog and I get a log with this conntent


------------------------------------------------------------
25/05/2016 22:17:12: EXCESS RELEASE OF FONT Ms Sans Serif[ hFont : 0] ( nCount : -2 )
<-TFONT:END(284) <-TCONTROL:DESTROY(2132) <-TBTNBMP:DESTROY(925) <-TWINDOW:HANDLEEVENT(0) <-TCONTROL:HANDLEEVENT(1733) <-TBTNBMP:HANDLEEVENT(1731) <-_FWH(3288) <-WINRUN(0) <-TWINDOW:ACTIVATE(1038)
------------------------------------------------------------
29/05/2016 21:07:40: EXCESS RELEASE OF FONT ARIAL[ hFont : 0] ( nCount : 0 )
<-TFONT:END(284) <-TCONTROL:DESTROY(2132) <-TBTNBMP:DESTROY(925) <-TWINDOW:HANDLEEVENT(0) <-TCONTROL:HANDLEEVENT(1733) <-TBTNBMP:HANDLEEVENT(1731) <-_FWH(3288) <-WINRUN(0) <-TWINDOW:ACTIVATE(1038)
------------------------------------------------------------
29/05/2016 23:10:26: EXCESS RELEASE OF FONT ARIAL[ hFont : 0] ( nCount : 0 )
<-TFONT:END(284) <-TCONTROL:DESTROY(2132) <-TBTNBMP:DESTROY(925) <-TWINDOW:HANDLEEVENT(0) <-TCONTROL:HANDLEEVENT(1733) <-TBTNBMP:HANDLEEVENT(1731) <-_FWH(3288) <-WINRUN(0) <-TWINDOW:ACTIVATE(1038)
------------------------------------------------------------


I don't know how I can eliminate the resource more times that I created it, I will appreciate some commentregards

Marcelo
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Problem with font

Posted: Mon Jun 13, 2016 04:02 AM

There is absolutely no problem with creating a font once in a global variable like oApp:oFont and then destroying it at the end of the program. This should work perfectly.

I think we all know the rules, but the issue is how do we ensure that our program strictly follows this discipline.

Please ensure that:
1) Font created by the application should be released by the application once. Only once, not more or less.
That means: If we created a global font variable and release it at the end of the program, we should not explicitly release that font any where inside the program either by oFont:End() or RELEASE FONT oFont.

2) Wherever we want to use that font, we should either assign the font in the COMMAND or oObj:SetFont( oFont ).
Do not assign the font directly to any control/dialog or window.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 01:39 PM
Mr. Rao.

many thanks for the explanation. You can see that I get ( nCount : -2 ), this means that I release the font more times than I create or use, but how you say, I only create one time and release one time.

Maybe my problems is that I change the say's fonts of the dialogs without defined (redefine) it

Code (fw): Select all Collapse
 DEFINE DIALOG .....

 ACTIVATE DIALOG oSelf:oForm CENTER NOWAIT;
            ON INIT  FindControlsById( oSelf:oForm, oApp():oFont6B ) 

......
//------------------------------------------------------------------------------
function FindControlsById( oDlg, oFont )
//----------------------------------------------------------------------------//GW_HWNDNEXT END
   LOCAL hCtrl := GetWindow( oDlg:hWnd, GW_CHILD ), hdc

   //TVM_SETTEXTCOLOR

   WHILE hCtrl != 0
      IF GetClassName( hCtrl ) == "Static" .AND. GetWindowLong( hCtrl, GWL_ID ) == 65535
         SendMessage( hCtrl, WM_SETFONT, oFont:hFont )
         hdc = GetDC( hCtrl )
         SetTextColor( hdc, RGB(255,0,0) )
         RELEASEDC( hCtrl, hdc )

         //SetBkColor(hdc, CLR_BLUE )
         SendMessage( hCtrl, 312, RGB(255,0,0) )
      ENDIF
      hCtrl := GetWindow( hCtrl, GW_HWNDNEXT )
   ENDDO


Other question, how you can see, I try to change the color too, but can I only change the font type, not the color, are there the option to do than without define (redefine) the controls (says)

Regards

Marcelo Vía
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 01:52 PM

Marcelo,

Why don't you just define a different global font just for SAYs?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 02:24 PM

James,

simply to save time and code, in this way you don't need to assign id to the text (label) resource and don't need to redefine the says in the code, but all the points of view are correct

regards

Marcelo Vía

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 05:45 PM

Marcelo,

I am wondering why you can't just pass two fonts to your current function and just add logic to use then new font for SAYs?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 06:33 PM

James,

maybe I cant not understand you, but my problems is not if we can define global fonts, local or pass it, the problems is how we can manage it, because I use no modal dialog some estrange behavior occur, like the internal counter of font utilization go to negative, and the same effects showed by Silvio.

I only create the font one time and I release it one time

Regards

Marcelo

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem with font

Posted: Mon Jun 13, 2016 10:02 PM

Marcelo,

OK, now I see the issue.

As I mentioned in a previous post, you should clone the global font before assigning it to a dialog.

Local oFont:= oClone( AppFont() )

This way when the dialog ends the font, it doesn't have any effect on the global font or the global font counter.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM

Re: Problem with font

Posted: Tue Jun 14, 2016 03:00 AM

James,

ok, I can see you suggestion, I will try this approach

Thanks

Marcelo Vía

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem with font

Posted: Tue Jun 28, 2016 12:46 AM

Maracelo,

I am just wondering if you solved this problem?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM

Re: Problem with font

Posted: Tue Jun 28, 2016 02:05 PM

James,

I start to proving to use local clone fonts, and I can say that all is more stable

thanks and regards

Marcelo Vía

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem with font

Posted: Tue Jun 28, 2016 03:25 PM

That's good news, Marcelo. Glad to hear it is working.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion