Problem with font

Problem with font

Postby Silvio.Falconi » Thu Jun 09, 2016 8: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 ::oFont: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

Image

AFTER

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with font

Postby James Bott » Thu Jun 09, 2016 2: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 ::oFont: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with font

Postby Marcelo Via Giglio » Mon Jun 13, 2016 3: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
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Problem with font

Postby nageswaragunupudi » Mon Jun 13, 2016 4: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
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Problem with font

Postby Marcelo Via Giglio » Mon Jun 13, 2016 1: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: Select all  Expand view


 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
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Problem with font

Postby James Bott » Mon Jun 13, 2016 1: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with font

Postby Marcelo Via Giglio » Mon Jun 13, 2016 2: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
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Problem with font

Postby James Bott » Mon Jun 13, 2016 5: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with font

Postby Marcelo Via Giglio » Mon Jun 13, 2016 6: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
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Problem with font

Postby James Bott » 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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with font

Postby Marcelo Via Giglio » Tue Jun 14, 2016 3:00 am

James,

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

Thanks

Marcelo Vía
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Problem with font

Postby James Bott » 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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Problem with font

Postby Marcelo Via Giglio » Tue Jun 28, 2016 2: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
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Problem with font

Postby James Bott » Tue Jun 28, 2016 3:25 pm

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

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 74 guests