Calling a function in an extended type in an array

Previous topic - Next topic

Moebius

...doesn't work if more than one 'symbol' is specified in the array's index.  The best way to describe this is with a few examples:

Code (glbasic) Select
// Extended type declaration...
TYPE ExtType

Var  // One variable...

FUNCTION Dummy:  // One function...
ENDFUNCTION

ENDTYPE

// Create the array...
LOCAL TypeArray[] AS ExtType
DIM TypeArray[1]

// Variables for demonstration:
LOCAL a = 0, b = 0, c = 0, d


d= TypeArray[0].Dummy() // Compiles
d= TypeArray[a].Dummy() // Compiles
d= TypeArray[a + b + c].Var // Compiles

d= TypeArray[0 + 0].Dummy() // Doesn't compile
d= TypeArray[ (0 + 0) ].Dummy() // Doesn't compile
d= TypeArray[0 * 0].Dummy() // Doesn't compile
d= TypeArray[a + b].Dummy() // Doesn't compile
d= TypeArray[ (a + b) ].Dummy() // Doesn't compile

KEYWAIT
END


The error produced is is "call to undefined function : ExtType".  You can quite easily get around it by using a temporary variable and passing that as the index, but seeing as this problem is specifically to do with functions in extended types, perhaps there's an only smallish code issue...
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Kitty Hello

can you use ALIAS before the call? Maybe?
Code (glbasic) Select

ALIAS ptr AS TypeArray[0 + 0]
d= ptr.Dummy() // Doesn't compile


With expressions, my precompiler is very weak. I hope for the GLB-Script language to behave better, so I can use his error messages XD.

bigsofty

Simplest way around this is to make a temp var for any calculations that as used are parameters, ala...

Code (glbasic) Select
foo=a + b + c; d= TypeArray[foo].Var

Edit: Whoops I really should read all of the post...  :S
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)