TYPE MString AS ZSTRING * 60
DECLARE SUB PrintMenu(MenuArray() AS MString)
DIM Menu(5) AS MString
Menu(1) = " In Order"
Menu(2) = " Random"
Menu(3) = " Missed"
Menu(4) = " All Missed"
Menu(5) = " Test"
FOR I% = 1 TO 5
PRINT "Menu(I%) = ";Menu(I%)
NEXT I%
PRINT
PRINT "Press Anykey to Use PrintMenu function"
SLEEP
PrintMenu Menu()
SLEEP
END
SUB PrintMenu(MenuArray() AS MString)
FOR I% = 1 TO 5
PRINT "MenuArray(I%) = ";MenuArray(I%)
NEXT I%
END SUB
#Lang "fblite"
TYPE MString AS ZSTRING * 60
DECLARE SUB PrintMenu(MenuArray() AS MString)
DIM Menu(5) AS MString
Menu(1) = " In Order"
Menu(2) = " Random"
Menu(3) = " Missed"
Menu(4) = " All Missed"
Menu(5) = " Test"
FOR I% = 1 TO 5
PRINT "Menu(I%) = ";Menu(I%)
NEXT I%
PRINT
PRINT "Press Anykey to Use PrintMenu function"
SLEEP
PrintMenu(Menu())
SLEEP
END
SUB PrintMenu(MenuArray() AS MString)
FOR I% = 1 TO 5
PRINT "MenuArray(I%) = ";(@MenuArray(0))[Sizeof(MString)*I%]
'or PRINT "MenuArray(I%) = ";*(@MenuArray(0) + Sizeof(MString)*I%)
NEXT I%
END SUB
Other formula if you want to kept the check of out-bounds on the array: PRINT "MenuArray(I%) = ";*(@MenuArray(I%) + (Sizeof(MString)-1)*I%)
or: PRINT "MenuArray(I%) = ";(@MenuArray(I%))[(Sizeof(MString)-1)*I%]
This is definitely a bug, related to #650. I can't say yet whether fixed-length string arrays passed as parameters can be implemented, but even if that's not possible then the compiler should show an error. At the moment it just fails silently...
#Lang "fblite"
Dim MString As zstring Ptr =Allocate(60)
Declare Sub PrintMenu(MenuArray() As Typeof(Mstring))
Dim Menu(5) As Typeof(MString)
Menu(1) = @" In Order"
Menu(2) = @" Random"
Menu(3) = @" Missed"
Menu(4) = @" All Missed"
Menu(5) = @" Test"
For I% = 1 To Ubound(menu)
Print "Menu(I%) = ";*Menu(I%)
Next I%
Print
Print "Press Anykey to Use PrintMenu function"
Sleep
PrintMenu(Menu())
Sleep
End
Sub PrintMenu(MenuArray() As Typeof(MString))
For I% = 1 To Ubound(MenuArray)
Print "MenuArray(I%) = ";*Menuarray(I%)
Next I%
End Sub
dodicat, the memory allocation (60 bytes) with as pointer 'MString' is useless (if we absolutely want declare an alternative name for 'Zstring Ptr', just define it with for example 'Type MString As Zstring Ptr'):
#Lang "fblite"
Declare Sub PrintMenu(MenuArray() As Zstring Ptr)
Dim Menu(5) As Zstring Ptr
Menu(1) = @" In Order"
Menu(2) = @" Random"
Menu(3) = @" Missed"
Menu(4) = @" All Missed"
Menu(5) = @" Test"
For I% = 1 To Ubound(menu)
Print "Menu(I%) = ";*Menu(I%)
Next I%
Print
Print "Press Anykey to Use PrintMenu function"
Sleep
PrintMenu(Menu())
Sleep
End
Sub PrintMenu(MenuArray() As Zstring Ptr)
For I% = 1 To Ubound(MenuArray)
Print "MenuArray(I%) = ";*Menuarray(I%)
Next I%
End Sub
#Lang "fblite"
Dim MenuPtr(5) AS Zstring Ptr
For I% = 1 To 5
MenuPtr(I%) = Callocate(60)
Next I%
DECLARE SUB PrintMenu(MenuArrayPtr() AS Zstring Ptr)
*MenuPtr(1) = " In Order"
*MenuPtr(2) = " Random"
*MenuPtr(3) = " Missed"
*MenuPtr(4) = " All Missed"
*MenuPtr(5) = " Test"
FOR I% = 1 TO 5
PRINT "*MenuPtr(I%) = ";*MenuPtr(I%)
NEXT I%
PRINT
PRINT "Press Anykey to Use PrintMenu function"
SLEEP
PrintMenu(MenuPtr())
SLEEP
For I% = 1 To 5
Deallocate(MenuPtr(I%))
Next I%
END
SUB PrintMenu(MenuArrayPtr() AS Zstring Ptr)
FOR I% = 1 TO 5
PRINT "*MenuArrayPtr(I%) = ";*MenuArrayPtr(I%)
NEXT I%
END SUB
SUB PrintMenu(MenuArrayPtr() AS ZSTRING PTR)
FOR i AS INTEGER = 0 TO UBOUND(MenuArrayPtr)
PRINT "*MenuPtr(i) = "; *MenuArrayPtr(i)
NEXT
END SUB
DIM AS ZSTRING PTR MenuPtr(...) = _
{ @" In Order" _
, @" Random" _
, @" Missed" _
, @" All Missed" _
, @" Test" _
}
FOR i AS INTEGER = 0 TO UBOUND(MenuPtr)
PRINT "*MenuPtr(i) = "; *MenuPtr(i)
NEXT
PRINT
PRINT "Press Anykey to Use PrintMenu function"
SLEEP
PrintMenu(MenuPtr())
SLEEP