Arrays Casten führt zu komischen Effekten

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

das wurgel

Betreff: Arrays Casten führt zu komischen Effekten

BeitragSo, März 06, 2011 21:26
Antworten mit Zitat
Benutzer-Profile anzeigen
Hab mich gerade gefragt, ob man Objekt-Arrays wohl casten kann. Ich probierte es und zu meiner Überaschung ging es wirklich, nur bleiben die Objekte, die von einem anderen Typ sind als das neue Array, im neuen Array erhalten. Das führt zu komischen Effekten:
Code: [AUSKLAPPEN]
SuperStrict


Local objarray:Object[]=new Object[3]

objarray[0]=new Type1
objarray[1]=new Type2
objarray[2]=new Type3


Local type1array:type1[]
type1array = type1[](objarray)


For Local obj:Object = EachIn type1array
   If Type1(obj) Then
      Print "Type 1" + " a="+Type1(obj).a
   ElseIf Type2(obj)
      Print "Type 2" + " b="+Type2(obj).b
   ElseIf Type3(obj)
      Print "Type 3" + " c="+Type3(obj).c
   EndIf
Next

Rem
Type 1 a=1
Type 2 b=2
Type 3 c=3
End Rem



Print

For Local t1:Type1 = EachIn type1array
   If t1<>Null Then Print "Type 1 a="+t1.a
Next

Rem
Type 1 a=1
Type 1 a=2
Type 1 a=3
End Rem



Print

For Local t1:Type1 = EachIn type1array
   Local obj:Object=t1
   
   If Type1(obj) Then
      Print "Type 1" + " a="+Type1(obj).a
   ElseIf Type2(obj)
      Print "Type 2" + " b="+Type2(obj).b
   ElseIf Type3(obj)
      Print "Type 3" + " c="+Type3(obj).c
   EndIf
Next

Rem
Type 1 a=1
Type 2 b=2
Type 3 c=3
End Rem



Type Type1
   Field a%=1
End Type


Type Type2
   Field b%=2
End Type


Type Type3
   Field c%=3
End Type
1 ist ungefähr 3

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group