Starting with the FBeginner Book (PDF format below) is still a good way to learn FreeBASIC. Some topics in the book are probably deprecated by now or even missing, but it maybe worth reading for anyway.
- Freebasic Beginners Guide (FBeginner.pdf file)
- FBeginner is a concise, hands-on beginner's guide to FreeBasic and is aimed at the novice programmer. The book assumes no prior programming knowledge.....
Indexes of Advanced Articles from Documentation Forum
The list below provides links to all the tutorial / teaching / pedagogical topics that have been grouped in the Documentation forum.
These such topics were developed for the most part from topics already existing in all forums by rewording and complementing, in order to create draft articles for documentation.
- How to Manage a Critical Section of the code of a Thread in FB (article of 7 posts)
- A critical section is a part of a multi-threading program that may not be concurrently executed by more than one of the program processes (it's a piece of a program that requires mutual exclusion of access).
Typically, the critical section accesses a shared resource, such as a data structure, a peripheral device, or a network connection, that does not allow multiple concurrent accesses.....
- How to Overload the Operator '->' (ptr to member access) and Build a Smart Pointer in FB (article of 1 post)
- The operator '->' (pointer to member access) is used to access any member of an object (instance) via a pointer to this instance (under normal circumstances, the left operand of this operator must be a pointer to an object instance).
Overloading of this operator allows you to create a pointer wrapper class and let it behave like the pointer itself.....
- How to Solve the Flickering Issue when Refreshing a Window in FB Graphics Mode (article of 1 post)
- Refreshing (redrawing without precaution) a window in graphics mode can result in annoying flickering (this is due to the display of unwanted intermediate images picked up during the user refreshing phase).
The phenomenon is obviously intensified if the entire window is first erased before being completely updated, and this repeatedly.....
- How to Use 'On [Local] Error Goto' statement in FB (article of 1 post)
- 'On [Local] Error Goto label' causes a program jump to a specified label as soon as an error occurs. Such errors can be triggered by built-in statements such as 'Open', 'Get', 'Put', or when the 'Error' statement is used.
The error checking for built-in statements is only enabled if the program is compiled with one of the '-e', '-ex' or '-exx' options. Otherwise, no jump will be performed, but the command will still consume processor time.....
- How to Debug Macro at Compile Time in FB (article of 1 post)
- Macros offer a powerful way to extend the language and create reusable code. One reason macros are used is performance.
They are a way of eliminating procedure call overhead because they are always expanded in-line. There is no alternative for this in FreeBASIC because it does not support inline procedures.
Using macros can be extremely unsafe and they hide a lot of pitfalls which are very hard to find.....
- How to Use the Lbound / Ubound Size information of Array in FB (article of 1 post)
- LBound / UBound returns the lower / upper values of size information for an array: the dimension of the array (number of usable indexes) and the index bounds for each dimension. The array name is specified in the first parameter, and the dimension selection in the second parameter.
These sizing information are available both for a fixed-length array (sizing fixed at compile-time) and for a variable-length array (bounds sizing adjustable during run-time).....
- How to Use some Implicit Conversion for getting compatibility from Zstring to Ubyte in FB (article of 1 post)
- Since the introduction of the Zstring type in FreeBASIC by v1ctor (through already fbc version 0.13 beta in April 2005!), this compatibility from Zstring to Ubyte exists (if using particular syntax recalled a little from time to time).
Some people may have used it consciously. No doubt more people did so by inattention, not realizing that they were in principle making an invalid and forbidden assignment, but luckily corrected under the hood by an implicit conversion rule of compiler that was unknown to them.....
- How to Manage Dynamic Memory (Allocation / Deallocation) in FB (article of 1 post)
- FreeBASIC supports three basic types of memory allocation:
- Static allocation occurs for static/global variables. Memory is allocated once when the program runs and persists throughout the life of program.
- Stack allocation occurs for procedure parameters and local variables. Memory is allocated when the corresponding block is entered, and released when the block is left, as many times as necessary.
- Dynamic allocation is the subject of this article.....
- How and Why to Define Constructors, Assignment-Operators, and Destructor, for UDTs in FB (article of 1 post)
- Some member procedures, which have a predefined name in the Type, have a specific role that is constructing, assigning, and destroying objects. These are the constructors, the assignment-operators, and the destructor.
Of these, some are special because a version will be automatically built by the compiler if they are needed and not explicitly defined by the user. These are the default-constructor, the copy-constructor, the copy-assignment operator, and the destructor.
This article takes into account Type inheritance and virtuality.....
- How to properly Use Dynamic (variable-length) Arrays in FB UDTs (article of 1 post)
- When declaring a dynamic (variable-length) array member in a Type, 'Any' must be always specified in place of the array bounds in order to create a dynamic array with a certain amount of dimensions that is determined based on the number of 'Any' specified.
In FreeBASIC, Type data structures must ultimately be fixed-size, such that compiler knows how much memory to allocate for objects of that Type.
Nevertheless, a Type may contain dynamic (variable-length) field members: strings and even arrays.....
- How to Manage FB Reusable Procedures by Including Source Modules (vs. compiled modules) (article of 1 post)
- When old OSs (like DOS) were used, compiling by separate modules was mandatory as soon as the program was not very short, because of the small memory size available for the compiler (about 200 KB with Quick Basic 4.5).
Now, with modern PC and OS, this compilation limit is pushed back by a factor of about 10000, and the compile time of a large file in one go has become acceptable especially with FreeBASIC.
This allows to use another method (than a library of compiled files) to manage the reusable user procedures. One other reason with FreeBASIC (as many other languages) is it does not support multiple inheritance.....
- How to properly Choose between Composition, Aggregation, and Inheritance, for UDTs in FB (article of 1 post)
- Complex type structures can be built through composition, aggregation, and inheritance.
Composition or aggregation (specialized form of association) is the process of creating more complex types from simple ones, while inheritance is the process of creating more complex type by acquiring the attributes and behaviors of existing ones.
There is a very famous design principle which says “Favor composition over inheritance“, or also "Don’t use inheritance just to get code reuse". One other reason to favor composition with FreeBASIC (as with many other languages) is it does not support multiple inheritance.....
- How and Why to make Abstraction by Object Encapsulation, with FB Syntax in UDTs (basics) (article of 1 post)
- Abstraction is a way of expressing a task without showing the underlying implementation details. For example, adding two vectors is the two-by-two addition of each of its components. Its abstraction is the overload of the + operator for the vector Type/Class.
Encapsulation is a way of facilitating abstraction. A Type/Class is forced to hide its internal elements (in the private part of the Type/Class) so that a user of the Type/Class is forced to go through the abstractions that have been defined (the public part of the Type/Class) to use it.....
- How and Why to make Abstraction by Subtype Polymorphism, with FB Syntax in UDTs (advanced) (article of 1 post)
- Subtype polymorphism is the concept of providing a single interface to entities that can have different types (abstraction). More precisely, a same interface is implemented by a member routine having the same identifier in each type belonging to the same inheritance hierarchy.
Thanks to the abstract/virtual procedures, one can write a code using only the base type that will automatically call the derived type procedures.
By using the same procedure name for several different types, the polymorphism allows a much more generic programming (abstraction). The coder does not have to know, when calling a base procedure, the precise type of object on which the procedure will apply. He just needs to know that this type will implement the procedure.....
- Why, When and How to Declare / Implement Constructors, Destructor, ..., for UDTs in FB (advanced) (article of 1 post)
- The default constructor and the destructor are two special member procedures that are called to the creation and the destruction of an object.
Any type has an implicit default constructor and an implicit destructor provided by the compiler if they are needed and not overloaded by user.
These constructors and destructors call the default constructors and destructors of the base types and type member data, but apart from that, they may eventually do nothing else.
It is therefore often necessary that user defines an explicit default constructor and an explicit destructor, in order to execute actions that must take place during the creation of an object and their destruction.....
- How FB supports References (pass and return byref, byref variables), and How to Use them (article of 1 post)
- References and pointers are closely related. Indeed, a variable and its different references have the same address, since they allow access to the same object. In FB, a reference is implemented under the hood through an internal pointer which holds the address of the variable.
To use a reference to manipulate an object is therefore the same as manipulating a pointer containing the address of this object.
The reference encapsulates the manipulation of the address of the variable and is used as a dereferenced pointer. The difference lies here in the fact that one does not have to perform the dereferencing.
References are much easier to handle than pointers, so they make code much safer.....
- How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB (article of 1 post)
- Iteration and recursion are two very useful ways to program, especially to perform a certain number of times a certain script, and thus allow optimization of the code. If iteration is relatively easy to understand, recursion is a concept not necessarily obvious at the beginning.
When speaking of a recursive procedure (sub or function), we refer to a syntactic characteristic: the procedure, in its own definition, refers to itself (it calls itself).
But when talking about recursive process, linear or tree, we are interested in the process flow, not in the syntax of the procedure's writing.
Thus, a procedure can have a recursive definition but correspond to an iterative process.....