I am just getting started with classes in pbwin9 and was wondering what I'm doing wrong. I'm working on building a stringlist class. Internally the list is stored as an array. The example below crashes (win vista) with a "the program is not responding" message immediately when run. I tried putting message boxes in the constructor and the crashing functions, but get the same crash. It seems whenever the object is referenced, it crashes. Hopefully I'm just doing something easy and stupid.
Tia,
Don
Tia,
Don
Code:
' ' c_stringlist.bas ' #compile exe #dim all class CStringList instance m_count as long instance m_strings() as string '-------------------------------------------------------------------------- '- constructor class method CREATE() dim m_strings(0 to 0) as instance string m_count = 0 end method '-------------------------------------------------------------------------- '- destructor class method DESTROY() erase m_strings() end method '-------------------------------------------------------------------------- interface I_STRING_LIST inherit CUSTOM '----------------------------------------------------------------------- method add(stringValue as string) incr m_count redim preserve m_strings(0 to m_count) as instance string m_strings(m_count) = stringValue end method '----------------------------------------------------------------------- method count() as long method = m_count end method '----------------------------------------------------------------------- method countAsString() as string method = trim$(str$(m_count)) end method '----------------------------------------------------------------------- property get value ( byval iWhich as long ) as string if (iWhich > ubound(m_strings)) and (iWhich <= ubound(m_strings)) then property = m_strings(iWhich) else property = "" end if end property '----------------------------------------------------------------------- property set value ( byval iWhich as long, byval sValue as string ) if (iWhich > ubound(m_strings)) and (iWhich <= ubound(m_strings)) then m_strings(iWhich) = sValue end if end property end interface end class function pbmain() dim lstString as I_STRING_LIST let lstString = class "TStringList" '- unremming this will cause a crash ''lstString.add "Test" '- unremming this will cause a crash 'msgbox "List contains: " + lstString.countAsString + $cr + "1=" + lstString.value(1) '- this causes a crash msgbox "Ok: " + lstString.countAsString end function
Comment