New wfxFont

Started by SeaVipe, August 22, 2022, 03:33:58 PM

Previous topic - Next topic

SeaVipe

Hello,
I'm not quite sure what I'm doing wrong here; this works but crashes my app when the form closes:
' a sub form.
Dim wfxF as wfxfont Ptr
wfxF = New wfxFont( "Consolas", 11, FontStyles.Normal, FontCharset.Ansi )
.txtID.Font  = wfxF
Delete wfxF
It also works fine if "Delete wfxF" is removed but the form can only be opened once as the app crashed on a second attempt to open it.

This works just fine:
.txtID.Font            = New wfxFont( "Courier New", 11, FontStyles.Normal, FontCharset.Ansi )

This isn't mission-critical, I'm more interested in what I'm doing wrong.
Clive Richey

Paul Squires

From the looks of it you are assigning the wfxF pointer to the .txtID.Font. HOWEVER, this does not make a copy of the pointer. It is the actual pointer to the new font. Once you DELETE wfxF then the pointer memory is cleared and becomes invalid, but wait, you also assigned that same pointer to .txtID.Font so that now becomes invalid as well.

Removing the DELETE is the correct thing to do. You could then DELETE the font prior to the form closing by retrieving it from .txtID.Font, or you could simply not DELETE it because I am pretty sure that when your txtID control is destroyed then the Font held in .txtID.Font will also be DELETE'd  (I not near my source code but I think this is what happens).

 
Paul Squires
PlanetSquires Software