FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Is it still required to destroy Font object ?
Posts: 115
Joined: Mon Oct 17, 2005 04:42 AM
Is it still required to destroy Font object ?
Posted: Tue Nov 15, 2005 10:10 AM

Hi,

Is it still required to destroy Font object to release memory occupied by it ? I am using Jun-2005 build.

TIA
Milan.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Is it still required to destroy Font object ?
Posted: Tue Nov 15, 2005 11:11 AM

Yes for fonts created by yourself and used "on the fly", ie. not assigned to any controls.

EMG

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Is it still required to destroy Font object ?
Posted: Mon Jan 04, 2010 09:39 PM

Does this mean if the program is terminated with oWnd:end() that the FONT is still occupying the memory?
Is there a function to know which Fonts one have ceated?

Thanks in advance
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Is it still required to destroy Font object ?
Posted: Mon Jan 04, 2010 10:00 PM

Otto,

In this thread we explain how to check all created GDI objects:

viewtopic.php?f=3t=15935start=0hilit=gdi+resources

&&&

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Is it still required to destroy Font object ?
Posted: Mon Jan 04, 2010 10:22 PM

Antonio,
I don’t understand exactly when a FONT has to be released.
If I look into the new tribbon classe I see that ::oFont is created.
How is this Font released?

If I use for example:
Func test(oFont)
Local oFont1
oFont1:=oFont
return nil

Do I have 2 fonts and must I release oFont1?
Thanks in advance
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Is it still required to destroy Font object ?
Posted: Mon Jan 04, 2010 10:40 PM
Otto,

If you mean this font in Class TRibbonBar:
Code (fw): Select all Collapse
   if ::oFont == nil
      ::oFont := TFont():New()
      ::oFont:hFont := GetStockObject( DEFAULT_GUI_FONT )
   endif

there is no need to destroy it as it uses a Windows own hFont.

If you create a font using:
Code (fw): Select all Collapse
DEFINE FONT oFont NAME ... SIZE ..., ...

then after is used by an object (window, dialog, control, printer) you have to destroy it yourself:
Code (fw): Select all Collapse
oFont:End()

Fonts reuse their hFont handles to reduce GDI memory consume, using a counter which gets incremented when the font is assigned to an object and decremented when the object is End()ed. But when we do oFont:End() then the counter is decreased to zero and then it is really destroyed
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Is it still required to destroy Font object ?
Posted: Mon Jan 04, 2010 10:59 PM
Hello Antonio,

Thank you for your help.

I use 2 methods to paint my booking plan:
paint + paintChart
Depending on some conditions I use
::paintChartFont := ::oFont
Or
::paintChartFont := ::planFont

Does this assignment always create a new font ?
Thanks in advance
Otto

Code (fw): Select all Collapse
METHOD paint()

   do while .not. EOF()
      IF PLAN_DB->jahrgang4 = "MELD"
         ::paintChartFont := ::oFont
       else
         ::paintChartFont := ::planFont
       ENDIF

      ::PaintChart(  )
      skip

   ENDDO

return nil
//----------------------------------------------------------------------------//

METHOD PaintChart()
   hOldFont := SelectObject( ::oWnd:hDC, ::paintChartFont:hFont )

   DrawText( ::oWnd:hDC, cChartCaption,{ nCurRow - 6 ,;
      StartPX + nTemp ,;
      nCurRow + ::nRowHeight ,;
      StartPX + nDurationPX + ::nColWidth/2 - 2  }, nStyle  )

   SelectObject(  ::oWnd:hDC, hOldFont )
   DeleteObject( hOldFont )
return nil

//----------------------------------------------------------------------------//
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Is it still required to destroy Font object ?
Posted: Tue Jan 05, 2010 12:07 AM

Otto,

No, you are just creating an alias for the same font object.

To create a copy of an object:

oNew := oClone( oObject )

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Is it still required to destroy Font object ?
Posted: Tue Jan 05, 2010 07:03 AM

James,
Thank you James for explaining this to me.
Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Is it still required to destroy Font object ?
Posted: Tue Jan 05, 2010 07:20 AM

James, Otto,

Please be aware that oClone() should not be used with Windows handles as those can't be "cloned" :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Is it still required to destroy Font object ?
Posted: Tue Jan 05, 2010 04:58 PM

Antonio,

Thanks for pointing that out. Very important!

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion