PDA

View Full Version : Resource Keyword



marcuslee
02-12-2009, 18:19
In trying to change the font of a particular label, I came across a thread from 2007 (http://community.thinbasic.com/index.php?topic=612.0). In that thread, Petr used an example with the following line:



DIM hFont1 AS DWORD resource = Font_Create("Courier New", 9)


I'm curious about the keyword "resource." I found a comment from Eros (http://community.thinbasic.com/index.php?topic=250.0)when he implemented this feature. He wrote:



New way to declare DWORD or LONG variables used to reference resources like fonts: DIM MyVar AS DWORD RESOURCE
If RESOURCE is specified after DWORD or LONG types, thinBasic will take care of resource release when scope of the variable will end.


Is there any other time that it would be good to use RESOURCE other than fonts? Does RESOURCE offer some advantage for any LONG or DWORD declaration?

Love thinBasic! :occasion:


Mark

ErosOlmi
02-12-2009, 19:05
Yes there are other cases.

RESOURCE after DWORD or LONG instruct thinBasic to call DeleteObject (http://msdn.microsoft.com/en-us/library/dd183539(VS.85).aspx) API function so RESOURCE can be used in all cases you (the programmer) should diligently use DeleteObject

Ciao
Eros

marcuslee
02-12-2009, 19:42
RESOURCE after DWORD or LONG instruct thinBasic to call DeleteObject (http://msdn.microsoft.com/en-us/library/dd183539(VS.85).aspx) API function so RESOURCE can be used in all cases you (the programmer) should diligently use DeleteObject


Well, I am a sloppy programmer, so maybe RESOURCE is a good thing.


Mark :shock: