Yep
max2d.bmx is where I found it as shown and explained in my post of 2005-06-20.
Once more in a bit more detail.
g is a Local variable of type TGraphics. It is declared and set to the value returned by CreateDisplayGraphics(...) in the line:
If the value returned is null then the next little test will throw an exception
displayGraphics is a Global variable declared earlier in this module. It is of type TMax2dGraphics. Importantly TMax2dGraphics is derived from type TGraphics.
You can see the definition of TMax2dGraphics earlier in this module while the definition of TGraphics is in graphics.bmx.
Now comes the bit that apparently confuses you.
Here TMax2DGraphics() is a function call. Each type has an implicitly defined function like this that performs type casting. It tries to find a type in the inheritence path of the given parameter that matches the type in question.
If successful then the object will be returned. If not the function returns null.
So then displayGraphics now either refers to an object of type TMax2dGraphics or it is null.
Note that this is not a constructor because no object has been creeated. The object will have been created previously as the object of the derived type was itself created.
The code continues with testing whether the cast was sucessful and if so using it to prepare the graphics.
One final bit - the fact that CreateDisplayGraphics can return a value that is compatible with TGraphics but is actually of the more derived type TMax2dGraphics is just part of the basic mechanics of OO.
And that is it. Just proper and quite clever OO code. Not a constructor with a parameter although we can all hope for that to be introduced one day in a future version.
max2d.bmx is where I found it as shown and explained in my post of 2005-06-20.
Once more in a bit more detail.
g is a Local variable of type TGraphics. It is declared and set to the value returned by CreateDisplayGraphics(...) in the line:
Local g:TGraphics=CreateDisplayGraphics( width,height,depth,hertz,0 )
If the value returned is null then the next little test will throw an exception
If Not g Throw "Unable to create graphics" EndIf
displayGraphics is a Global variable declared earlier in this module. It is of type TMax2dGraphics. Importantly TMax2dGraphics is derived from type TGraphics.
Type TMax2dGraphics Extends TGraphics
You can see the definition of TMax2dGraphics earlier in this module while the definition of TGraphics is in graphics.bmx.
Now comes the bit that apparently confuses you.
displayGraphics=TMax2DGraphics(g)
Here TMax2DGraphics() is a function call. Each type has an implicitly defined function like this that performs type casting. It tries to find a type in the inheritence path of the given parameter that matches the type in question.
If successful then the object will be returned. If not the function returns null.
So then displayGraphics now either refers to an object of type TMax2dGraphics or it is null.
Note that this is not a constructor because no object has been creeated. The object will have been created previously as the object of the derived type was itself created.
The code continues with testing whether the cast was sucessful and if so using it to prepare the graphics.
One final bit - the fact that CreateDisplayGraphics can return a value that is compatible with TGraphics but is actually of the more derived type TMax2dGraphics is just part of the basic mechanics of OO.
And that is it. Just proper and quite clever OO code. Not a constructor with a parameter although we can all hope for that to be introduced one day in a future version.