Const values are first of all variables
A constant is a meaningful name that takes the place of a number or string that does not change. Although a constant somewhat resembles a variable, you can't modify a constant or assign a new value to it as you can to a variable. To protect the constant GFA-BASIC won't let you obtain the address of the constant using V: or VarPtr. In GFA-BASIC a constant is a write protected initialized variable. This means that a constant can be used in places where a variable can be used, but it cannot always be used where a literal value is used! During compile time the constant is not replaced with its value, but instead is used as variable. This is important when you use pointer initialization. For instance:
Dim pi as Pointer Int = $432178 ' allowed
Const addr = $432178
Dim pi2 as Pointer Int = addr ' not allowed
Do not make the mistake to interpret a Const as a C compatible #define.
Use the Handle data type as much as possible
Another aspect where GFA-BASIC 32 differs from VB is the inclusion of the primitive data type Handle. The Handle data type is a 32-bits integer value (Int32, Long) used to store a Windows API HANDLE data type. A WINAPI handle is a number that identifies an object. Because you won't want to perform math on an identification number and introduce hard to find bugs in your program, you should store such a value in a Handle data type. The thing is GFA-BASIC 32 protects against any form of calculation with a Handle type and shields the value from abuse.
Why is this important? I recently came across a VB source that used a local Long variable to store a Form handle and then used the same variable in a For-Next loop later on in the same Sub. This is a typical form of abuse and made the source hard to understand.
The Handle data type is storage type for 32-bit identifier values and is usually used to store return values from Windows API calls. Assigning values to a Handle is allowed but not conform the 'rules'. The only value a Handle is assigned to is Null; an indication that the variable doesn't contain a valid handle. Null is therefor a special GFA-BASIC keyword.
Dim hFnt As Handle = GetStockObject(SYSTEM_FONT) hFnt = Null ' invalidate handle
