Is this function Ok for cloning Font?
Correct. But we should know that we are not creating a totally new object with totally new :hFont. This function actually returns the same object with its internal counter :nCount incremented.
Actually, the internal method :Modify() achieves the same effect.
oClone := Clone_Font( oArial ) // your method
is exactly same as
oClone := oArial:Modify() // inbuilt method without parameters.
Example:
DEFINE FONT oArial NAME "ARIAL" SIZE 0,-12
? oArial:nCount // --> 1
oClone := Clone_Font( oArial )
? oArial:nCount, oClone:nCount // --> 2, 2
? oArial:hFont == oClone:hFont // --> .T.
? HB_ArrayID( oArial ) == HB_ArrayID( oClone ) // --> .T.
( That means oArial and oClone two variable names referring to the same object)
oArial:End() // This is same as oClone:End()
? oArial:nCount, oClone:nCount // --> 1, 1
oArial:End() // This is same as oClone:End()
? oArial:nCount, oClone:nCount // --> 0, 0
? oArial:hFont, oClone:hFont // --> 0, 0
This is what we know from this:
oClone := oArial
Both oClone and oArial refer to same Font Handle and same font object but the internal counter (nCount) is not effected.
Single oArial:End() or oClone:End() is enough to Release this font resource.
oClone := Clone_Font( oArial ) ( same as oClone := oArial:Modify() )
Both oClone and oArial refer to same Font Handle and same font object but the internal counter (nCount) is incremented by 1.
That means we need to call oClone/oArial:End() twice to release the font resouce.
This is equivalent to
oClone := oArial
oArial( or oClone):nCount++