How does one release a font created with FONT NEW without generating error 5 (illegal function call)? I've tried GRAPHIC DETACH and GRAPHIC BITMAP END before FONT END hndl but still get error 5.
Announcement
Collapse
No announcement yet.
Font End
Collapse
X
-
Code:GRAPHIC SET FONT fnthndl2& FONT END fnthndl1&
Rod
In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.
Comment
-
This has also come up here before.
I think it was answered by someone cutting and pasting from the doc for FONT END:
If the specified font is still in use by a control, a Graphic Control, a Graphic Window, or an XPrint page, an error 5 (Illegal Function Call) will be generated.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
This has also come up here before.
A very good example of why we should use the TAGS feature.
Also, some of us learn by repetition, and some of us learn by repeatedly trying to help.Rod
In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.
Comment
-
You need to have one temporary font which can be used to with GRAPHIC SET FONT so the other fonts can be freed. Even GRAPHIC DETACH does not prevent the #5 runtime error.
Here is a trick.
Use this subroutine instead of GRAPHIC SET FONT.
Code:SUB GraphicSetFont(BYVAL hFont&) STATIC hTempFont& IF hTempFont&=0 THEN FONT NEW "Times New Roman", 40, 1, 1, 0, 0 TO hTempFont& END IF IF hFont&=0 THEN hFont&=hTempFont& GRAPHIC SET FONT hFont& END SUB
I took a little code from a PB sample app (textrotate.bas) and modified it to use my subroutine above.
ie.
Code:CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1,"", 0, 0, 500, 400 GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1 GRAPHIC CLEAR RGB(192, 0, 0) GRAPHIC BOX (0, 0) - (80, 400),,RGB(0, 0, 64), RGB(0, 64, 128) GRAPHIC COLOR %YELLOW, -2 FONT NEW "Times New Roman", 40, 1, 1, 0, 900 TO hFont900 ' ---------------------- GraphicSetFont hFont900 ' ---------------------- GRAPHIC SET POS (0, 400) GRAPHIC PRINT " PowerBASIC " FONT NEW "Times New Roman", 40, 1, 1, 0, 300 TO hFont300 ' ---------------------- GraphicSetFont hFont300 ' ---------------------- GRAPHIC SET POS (90, 180) GRAPHIC PRINT "Graphic Print" GRAPHIC SET POS (100, 250) GRAPHIC PRINT "in any angle!" ' ---------------------- GraphicSetFont 0 ' call routine with a value of zero to set temp font ' ---------------------- FONT END hFont900 FONT END hFont300 ' no #5 error generated
Comment
-
Or you could take advantage of the failure to create a font, from the documentation:
If the font creation fails, the value zero (0) is assigned to fhndl.
Code:#COMPILE EXE #INCLUDE "win32api.inc" FUNCTION PBMAIN () AS LONG GRAPHIC WINDOW "Fonty Python",100,100,300,200 TO hBMP??? FONT NEW "" TO hfontnew& FONT NEW "Lucida Console",12,2,0,1,100 TO hFont??? GRAPHIC ATTACH hBMP???,0 GRAPHIC COLOR %WHITE, %BLACK GRAPHIC SET POS (20,20) GRAPHIC SET FONT hFont??? GRAPHIC PRINT "HEY, NEAT!!" MSGBOX "Look, no error:"+$CRLF+ERROR$(ERR) GRAPHIC SET FONT hfontnew& 'comment out this line for error GRAPHIC COLOR %BLACK,%WHITE GRAPHIC PRINT "HEY, NEATER!!" FONT END hFont??? IF ERR THEN MSGBOX "Look, an ILLEGAL FUNCTION CALL error:"+$CRLF+ERROR$(ERR) ELSE MSGBOX "Honest, I didn't do nothing wrong!" END IF GRAPHIC WINDOW END END FUNCTION
Rod
In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.
Comment
-
I'm curiouos. What's the big deal about releasing a font, or not? It's 4 bytes. Have to use an awful lot of fonts to use up any significant amount of memory. It's not like tying up large bl;ock for text or graphics or something.
Just curiious.
===================================================
"There is no sincerer love than the love of food."
George Bernard Shaw (1856-1950)
===================================================It's a pretty day. I hope you enjoy it.
Gösta
My Ego Site: http://www.SwedesDock.comPB Newby Tips: http://www.swedesdock.com/powerbasic/pb_shortcuts.htmlJWAM: (Quit Smoking): http://www.SwedesDock.com/smokingLDN - A Miracle Drug: http://www.SwedesDock.com/LDN/
Comment
-
>What's the big deal about releasing a font, or not? It's 4 bytes
No, the HANDLE uses four bytes. What PowerBASIC stores at whereever that handle's data are located could contain a lot more.
That's why we use handles instead of "all the associated data." Much easier for the programmer to refer to an integer than to finding and using all the data associated with that object.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
>Here is a trick.
Minus eight marketing points.
When someone else does it, it's a trick; when you do it, it's a technique.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Originally posted by Michael Mattias View Post>Here is a trick.
Minus eight marketing points.
=================================
In rivers and bad governments,
the lightest things swim at top.
Ben Franklin
=================================It's a pretty day. I hope you enjoy it.
Gösta
My Ego Site: http://www.SwedesDock.comPB Newby Tips: http://www.swedesdock.com/powerbasic/pb_shortcuts.htmlJWAM: (Quit Smoking): http://www.SwedesDock.com/smokingLDN - A Miracle Drug: http://www.SwedesDock.com/LDN/
Comment
-
>When your program ends, any existing fonts are automatically destroyed by >PowerBASIC
Unless I'm mistaken...
... PB only has to do anything because it still supports Win 9x/ME, which "features" shared GDI objects. In "genuine 32-bit" Windows, I think the O/S will destroy the process' GDI objects when that process ends.
But it's still "good programming technique" to close what you open, release what you get and destroy what you create.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
But it's still "good programming technique" to close what you open, release what you get and destroy what you create.
DIALOG NEW
GRAPHIC WINDOW NEW
FONT NEW
GRAPHIC BITMAP NEW
WIFE KNEW
Before I did, I checked to see if PBForms issued a DIALOG END statement to go with the DIALOG NEW statement when it generates code and found that it doesn't.
So I decided not to say anything about "good technique" or "good trick".Rod
In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.
Comment
-
So I decided not to say anything about "good technique" or "good trick".
So... I looked over the original (poster had modified it for posting) and sheesh, you want to talk about lazy/sloppy? I simply MUST update that and comment it a little bit. The sample "works" but neither teaches anything nor is it terribly adaptable to anything resembling The Real World.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
>...you want to talk about lazy/sloppy?
Hmm, I think Mr. Christopher Carroll noticed the same thing... and has already done something about it...
Good job, sir.
MCMMichael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
The crux of this issue is really simple -- PowerBASIC will not allow you to destroy a font which is still in use. If the selected font for a GRAPHIC WINDOW were destroyed, what would happen if you then executed a GRAPHIC PRINT? It wouldn't be pretty. {smile} You must first execute a GRAPHIC WINDOW END. The same is true of fonts in Dialogs, Controls, and Printers.
It doesn't matter if the window is detached, as it could be re-attached. If a font is in use anywhere, it cannot be destroyed with FONT END.
Best regards,
Bob Zale
PowerBASIC Inc.
Comment
Comment