Author Topic: STATIC Class problem... Better get some Advil... :(  (Read 1068 times)

0 Members and 2 Guests are viewing this topic.

Brian Alvarez

  • Guest
STATIC Class problem... Better get some Advil... :(
« on: July 25, 2019, 07:21:29 PM »
 Hello Charles, i would like to create a static class (or a global class that is initialized AFTER its definition).

Code: [Select]
class THECLASS
    method constructor(int a)
    end method
end class

FUNCTION THESUB(byref THECLASS *v) AS INT
    ' nothing
END FUNCTION

' This works fine.
NEW THECLASS a(1)
THESUB(a)

' This raises compile-time error.
NEW STATIC THECLASS a2(2)
THESUB(a2)

The Static portion reports:

Code: [Select]
ERROR: ERROR: nesting error `endif` (no beginning)

WORD: endif
LINE: 209
FILE: "main source

It almost works if i do this:

Code: [Select]
dim static THECLASS a2 : a2.constructor(2)
THESUB(a2)

I can use the class a2 as normal... but then THESUB doesnt recognize it's datatype and rejects it as a parameter...

Code: [Select]
ERROR: ERROR: parameters mismatch for procedure thesub
params given : #theclass@1

OPTIONS:
thesub(theclass) returns int


WORD: a3
LINE: 210
FILE: "main source
« Last Edit: July 25, 2019, 07:32:16 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: STATIC Class problem... Better get some Advil... :(
« Reply #1 on: July 25, 2019, 11:12:14 PM »
Hi Brian,

A static class is much the same as a UDT:

The constructer and destructor can be invoked explicitly any time.

static THECLASS a2

Code: [Select]
class THECLASS
    method constructor(int a)
    end method
end class

FUNCTION THESUB(THECLASS *v) AS INT
    ' nothing
END FUNCTION

' This works fine.
NEW THECLASS a(1)
THESUB(a)
...
DEL a

static THECLASS a2
'THECLASS a2
'dim a2 asTHECLASS
a2.constructor(2)
THESUB(a2)

Brian Alvarez

  • Guest
Re: STATIC Class problem... Better get some Advil... :(
« Reply #2 on: July 26, 2019, 12:25:54 AM »

 Thanks Charles... the problem was that it doesnt work with explicit byref...

 if no explicit byref and no explicit byval, what is the difference?

Charles Pegge

  • Guest
Re: STATIC Class problem... Better get some Advil... :(
« Reply #3 on: July 26, 2019, 12:58:34 AM »
byref and byval are generally not used in C-style headers. (byval would be the default).

fun(byref myClass*a) would be the equivalent of fun(myClass**a)

byref is the default for Basic-style headers, as in PowerBasic

Brian Alvarez

  • Guest
Re: STATIC Class problem... Better get some Advil... :(
« Reply #4 on: July 26, 2019, 01:00:24 AM »

Got it. Thanks Charles.