Is it still required to destroy Font object ?

Is it still required to destroy Font object ?

Postby Milan Mehta » 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.
Milan Mehta
 
Posts: 115
Joined: Mon Oct 17, 2005 4:42 am
Location: India

Re: Is it still required to destroy Font object ?

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Is it still required to destroy Font object ?

Postby Otto » Mon Jan 04, 2010 9: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Is it still required to destroy Font object ?

Postby Antonio Linares » Mon Jan 04, 2010 10:00 pm

Otto,

In this thread we explain how to check all created GDI objects:
viewtopic.php?f=3&t=15935&start=0&hilit=gdi+resources
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Is it still required to destroy Font object ?

Postby Otto » 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Is it still required to destroy Font object ?

Postby Antonio Linares » Mon Jan 04, 2010 10:40 pm

Otto,

If you mean this font in Class TRibbonBar:
Code: Select all  Expand view

   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: Select all  Expand view

DEFINE FONT oFont NAME ... SIZE ..., ...
 

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

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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Is it still required to destroy Font object ?

Postby Otto » 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: Select all  Expand view
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

//----------------------------------------------------------------------------//
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Is it still required to destroy Font object ?

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

Re: Is it still required to destroy Font object ?

Postby Otto » Tue Jan 05, 2010 7:03 am

James,
Thank you James for explaining this to me.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Is it still required to destroy Font object ?

Postby Antonio Linares » Tue Jan 05, 2010 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Is it still required to destroy Font object ?

Postby James Bott » Tue Jan 05, 2010 4:58 pm

Antonio,

Thanks for pointing that out. Very important!

James
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 82 guests