Announcement

Collapse
No announcement yet.

class question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    > [string equate] is not allowed [in LET statement]...

    LET objvar = CLASS ClassName$

    The term ClassName must be specified as a quoted string literal, which is the name of a class ....

    String literal links to the page titled "Constants and Literals."

    I tried both the "string literals" and "string constants" links from there, but neither says you can use a string contant in place of it.

    Strange, I thought I remember reading in some part of help file that string equates may be used anywhere a string literal or string variable may be used.

    If that's not true, tell me with a straight face it's not totally silly that a program would accept a quoted string literal but not a string equate.

    MCM

    Leave a comment:


  • Charles Dietz
    replied
    Also in PROPERTY GET value() ...

    IF (iWhich > LBOUND(m_strings)) ...

    Leave a comment:


  • Dominic Mitchell
    replied
    let lstString = class $MY_CLASS_NAME
    In this case you are asking for trouble. That is not allowed.
    See the Help File entry for the LET statement.

    Leave a comment:


  • Michael Mattias
    replied
    [replace]
    let lstString = class "TStringList"

    with this one

    let lstString = class "CStringList"
    Or with
    Code:
    let lstString = class  $MY_CLASS_NAME
    Using inline literals = Asking for trouble

    Leave a comment:


  • Don Dickinson
    replied
    haha, thanks fred. that was stupid. i was trying to resolve a problem with instance'd arrays (also my bug) and in doing so i renamed the class. guess i didn't rename it everywhere

    thanks a bunch
    don
    Last edited by Don Dickinson; 26 Sep 2008, 04:03 PM.

    Leave a comment:


  • Fred Harris
    replied
    I'll tell you what really improves the functioning though, and that is replacing this line...

    let lstString = class "TStringList"

    with this one

    let lstString = class "CStringList"

    Leave a comment:


  • Fred Harris
    replied
    Just took a quick look Don, but I noticed a string parameter in Method Add(string) without a Byval override. I believe you need the Byval.

    Leave a comment:


  • Don Dickinson
    started a topic class question

    class question

    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
    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
Working...
X