I'm practicing OOP and was trying to create a simple String class. From what I can tell the instance is deleted right after it's created. Perhaps I'm using this incorrectly or I still don't understand, lol. It seems the new instance retains it's value, but no longer keeps it's methods/properties.
Code: Select all
class objString {
; Construction ----------------------------------------------------------------
__New(Value="") {
this.Value:=Value
MsgBox % "__New: " this.Value " (" this.Len ")"
return Value
}
; Properties ------------------------------------------------------------------
Len {
get {
return StrLen(this.Value)
}
}
; Methods ---------------------------------------------------------------------
Sub(Pos,Len="") {
return SubStr(this.Value,Pos,Len)
}
; Returns first Len characters of object string.
L(Len=1) {
return this.Sub(1,Len)
}
; Returns last Len characters of object string.
R(Len=1) {
return this.Sub(this.Len-Len+1,Len)
}
Find(String,Case=false,Pos=1,Occurrence=1) {
return InStr(this.Value,String,Case,Pos,Occurrence)
}
; Destruction -----------------------------------------------------------------
__Delete() {
MsgBox % "__Delete: " this.Value
}
}
testString:=new objString("Hello, world!")
MsgBox % """" testString """ is " testString.Len " characters long."
MsgBox % """" testString """ is " StrLen(testString) " characters long."