Extending TImage

BlitzMax Forums/BlitzMax Programming/Extending TImage

d-bug(Posted 2006) [#1]
Hello,
could someone please tell me why TImage always return Null, if i try to cast it:


I've tested several ways, but casting TImage doesn't seem to work.


Dreamora(Posted 2006) [#2]
If you check your class you will find out that TMyImage actually isn't handled as a fully TImage extend.

Add a function create for example that returns :TMyImage
On a correct extend, the compiler would already throw an error that function declaration differs (as TImage.Create returns :TImage) but it does not in that case.


rdodson41(Posted 2006) [#3]
Basically in TImage.Load you are creating a TImage, but not a TMyImage. So since image is really a TImage casting it to a TMyImage will return null. Its the old saying of how a square is a rectangle, but a rectangle is not a square.


Fabian.(Posted 2006) [#4]
TMyImage(TImage.Load(url,MASKEDIMAGE,255,0,255))
TImage.Load returns a TImage, so casting to TMyImage will return Null.

You could write an image wrapper:
Type TMyImage Extends TImage
  Field src:TImage

  Method DoThisForAllMethods ( Parameters )
    Return src.DoThisForAllMethods ( Parameters )
  EndMethod
EndType