With Free Basic, the constructor is always called. The default constructor has no parameters. Which constructor is called depends of the type of the parameter(s), if any, that you pass when you create an instance of the class. You can create an instance of the class with DIM or NEW.
If you use NEW, what you get is a pointer to the class:
DIM pObj AS MyClass PTR = NEW (<parameters>)
Being a pointer, you have to use the pointer syntax (->) with Free Basic:
<result> = pObj-><method name> (<parameters)
And free it with DEL, i.e, DEL pObj
With DIM, whitout NEW
DIM pObj AS MyClass ' default constructor
--or--
DIM pObj AS MyClass = <parameter> ' if there is only a parameter
--or--
DIM pObj AS MyClass = MyClass(<parameters>) ' if there are more than one parameter
You use the dotted syntax:
pObj.<method name>(<parameters>)
The object will destroy itself and call the destructor when it goes out of scope.
You can wrap it between SCOPE/END SCOPE if you want:
SCOPE
DIM pObj AS MyClass
pObj.<method name>
END SCOPE
and it will be destroyed as soon as the SCOPE block ends.
FUNCTION = needs of a copy constructor. Free Basic uses the overloaded operator LET (=).
OPERATOR LET (parameter)
This allows to return a copy of the class before it is destroyed.
FUNCTION Foo () AS MyClass
DIM pObj AS MyClass
....
FUNCTION = pObj
....
END FUNCTION
or, if you have a constructor that accepts, lets say, an string:
FUNCTION Foo () AS MyClass
DIM s AS STRING2
....
FUNCTION = s
....
END FUNCTION
It creates a temporary instance of the class and calls the LET operator to allow you to make a copy of the local string, that will be destroyed when the method ends.
RETURN also creates a temporary instance of the class, but instead of LET, it calls the appropriate constructor.
FUNCTION Foo () AS MyClass
DIM s AS STRING2
....
RETURN s
END FUNCTION
What you use depends of what you are going to return. STRING2 is garbage collected, so we don't need to worry to free it. But if we want to return a data type that we have to free, for example a VARIANT, if we use RETURN then VARIANT won't be cleared. Therefore, we can use:
FUNCTION Foo () AS MyClass
DIM v AS VARIANT
....
FUNCTION = v
VariantClear @v
END FUNCTION
Hope this helps.
I have used classes (in FB they are called TYPE) extensively, and my WinFBX framework has many of them that you can browse to see how they work.