"user type is not defined : TYPE is not declared" error

Previous topic - Next topic

bigsofty

Probably bad coding form but...

Code (glbasic) Select
LOCAL a AS P = P.Create( x, y )

Removing the "= P.Create( x, y )", seems to fix it.

*EDIT* spoke too soon,

the

Code (glbasic) Select
= P.Create( x, y )

causes the error.

Even this does not work...

Code (glbasic) Select
LOCAL a AS P
a = P.Create( x, y )


OK, here's a rough type to explain the above a bit more...

Code (glbasic) Select
TYPE P

x#
y#

FUNCTION Create AS P: x#, y#
LOCAL ap AS Point
ap.x=x
ap.y=y
RETURN ap
ENDFUNCTION

ENDTYPE


*EDIT 2*

Its OK, this works...

Code (glbasic) Select
LOCAL a AS P
a = a.Create( x, y )


Which kinda makes sense, my original line compiled on the previous compiler version, so I stuck with it.

That all being said, I would like to still use the syntax of my first line.  =D

Cheers,


Ian
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)

Slydog

I don't think GLBasic supports static types.
So, I think you need to declare an instance of the type before you call it's methods.
The type name itself can't be used to access the methods.

So, in theory, this should work:
Code (glbasic) Select
LOCAL a AS P = a.Create(x, y)

But since 'a' isn't declared yet in 'a.Create(x, y)' it may not work either.

Maybe you could create a global 'static' instance for this kind of usage:
Code (glbasic) Select
GLOBAL gP as P
...
LOCAL a AS P = gP.Create(x, y)
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

bigsofty

That's not a bad idea, I'll stick with the current solution but I'll use your method as a fallback if mine goes belly up.

Cheers,


Ian
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)

MrTAToad

It might be worth implementing, if only to make sure that there is no ambigious code when doing something like that.