I simulated OO classes in my final year project (written in DBPro)!
I had a template for each new "class" that I needed:
type M_class
name as string
id as integer
symbol as string
endtype
dim Mdata(0) as M_class
function M_new()
Mno=M_recycle()
if Mno=0
array insert at bottom Mdata(0)
Mno=array count(Mdata(0))
endif
endfunction Mno
function M_getSymbolIndex(s$)
Mno=0
m_len=M_size()
if m_len>0
for i=1 to m_len
if Mdata(i).symbol=s$
Mno=i
exit
endif
next i
endif
endfunction Mno
function M_recycle()
Mno=0
Mcount=M_size()
if Mcount>0
n=1
while (Mno=0) and (n<=Mcount)
if M_get(n)=0
Mno=n
endif
n=n+1
endwhile
endif
endfunction Mno
function M_kill(Mno)
m_len=M_size()
if Mno<=m_len and Mno>0
M_reset(Mno)
ok=1
else
ok=0
endif
endfunction ok
function M_reset(Mno)
m_len=M_size()
if Mno<=m_len and Mno>0
M_setName(Mno,"")
M_setId(Mno,0)
M_setSymbol(Mno,"")
ok=1
else
ok=0
endif
endfunction
function M_setName(Mno, value$)
m_len=M_size()
if Mno<=m_len and Mno>0
Mdata(Mno).name=value$
ok=1
else
ok=0
endif
endfunction ok
function M_setId(Mno, value)
m_len=M_size()
if Mno<=m_len and Mno>0
Mdata(Mno).id=value
ok=1
else
ok=0
endif
endfunction ok
function M_setSymbol(Mno, value$)
m_len=M_size()
if Mno<=m_len and Mno>0
Mdata(Mno).symbol=value$
ok=1
else
ok=0
endif
endfunction ok
function M_set(Mno, value)
m_len=M_size()
if Mno<=m_len and Mno>0
Mdata(Mno).=value
ok=1
else
ok=0
endif
endfunction ok
function M_getName(Mno)
m_len=M_size()
if Mno<=m_len and Mno>0
value$=Mdata(Mno).name
else
value$=""
endif
endfunction value$
function M_getId(Mno)
m_len=M_size()
if Mno<=m_len and Mno>0
value=Mdata(Mno).
else
value=0
endif
endfunction value
function M_getSymbol(Mno)
m_len=M_size()
if Mno<=m_len and Mno>0
value$=Mdata(Mno).symbol
else
value$=""
endif
endfunction value$
function M_get(Mno)
m_len=M_size()
if Mno<=m_len and Mno>0
value=Mdata(Mno).
else
value=
endif
endfunction value
function M_size()
output=array count(Mdata(0))
endfunction output
Note that originally the kill function was going to delete array elements if they were at the end of the Mdata(0) array. That command doesn't work at the minute! Instead I just set the attributes to blank or zero values.
Also note that my classes would have some sort of attribute (other than the three specified) that would indicate if it was in use. When recycling an old, blank object the line which reads "if M_get(n)=0" would have the name of the function I need to check if an object is in use. If the attribute was the id of the object then that line would read "if M_getId(n)=0".
I would add attributes to the type definition as needed. For example I use this system to manage my entities in-game. I could add an attribute to store the health of the entity. In this case I'd need some "get" and "set" functions for that, too.
Remember, that's a template with blanks that need to be filled. That's why the generic get and set functions don't assign anything to the value variable - until I use the blank function for something I don't know if it's going to be a string, a float or what.
I've used this approach in my project for loads of different things, even managing objects and images! Let me know if this is helpful!
Ending a sentence with a French word is so passé