• Derived Class

    By Thomas H Povlsen 2 decades ago

    Hi,



    Nice work, we are really appcreciating it here at my work.

    I am now incorporating the version 1.0 to our environment, using the possiblity of adding/altering functionallity with a derived class.



    I am having a problem though…..



    I override the constructor and some functions, and that is worknig fine

    But then i did a completely new function and when referencing this function in my agent i get a "Not a member" error.



    Any idea what my problem could be?



    I have done similar with ohter classes before with success.



    Thanks.



    /Thomas

    • Here are some things to look at

      By Julian Robichaux 2 decades ago

      Thomas -



      Thanks! I'm glad you're finding the application useful. Please tell your friends.

      :-)



      I'm assuming you're getting this error when you try to compile an agent, which is where I've seen this before. If that's not the case, please tell me.



      The obvious reason why this would happen is if your agent is referring to an old version of your subclass script library. To check this:


      1. comment out the line(s) in the agent where you're calling the offending method
      2. save and close your agent
      3. open the script library
      4. add a space or a linefeed somewhere in the script library (so it will force a recompile)
      5. save and close the script library
      6. reopen the agent (it's important that you actually closed it in step 2)
      7. uncomment out the method calls in the agent and try to recompile



        That's the obvious reason. If you've done this sort of thing before, that probably isn't what happened to you.



        Without seeing your specific code, it's hard to tell where the problem might lie, but consider this scenario:



        Let's say you added a simple method to the MailLogItem subclass example in the database that prints a string to the status bar:



        =============== CODE STARTS HERE ===============

        Class MailLogItem As LogItem

        ' …code…



        Function PrintToStatusBar (msg As String)
               Print msg<br/>
        
        End Function



        ' …code…

        End Class

        =============== CODE ENDS HERE ===============



        If you want to call that method in a simple example, you might be tempted to write an agent like this:



        =============== CODE STARTS HERE ===============

        Option Public

        Option Explicit



        Use "MailLogSubclass2"



        Sub Initialize

        Call UseMailLog("Julian Robichaux")

        Call globalLogItem.PrintToStatusBar("Hello")

        End Sub

        =============== CODE ENDS HERE ===============



        However, that won't compile (you'll get the old "Not A Member" error) because even though you called "Set globalLogItem = New MailLogItem" in the UseMailLog function, the compiler still thinks that globalLogItem is a member of the base LogItem class, which doesn't contain the PrintToStatusBar method.



        Here's a modification of the Initialize Sub that will compile and work as expected:



        =============== CODE STARTS HERE ===============

        Sub Initialize

        Call UseMailLog("Julian Robichaux")



        ' this won't work, because globalLogItem is technically a member

        '
        of the class LogItem, which doesn't have a PrintToStatusBar

        ' method defined

        '
        (You'll get the error "Not a member: PRINTTOSTATUSBAR")

        ' Call globalLogItem.PrintToStatusBar("Hello")



        ' this will work, because you're casting globalLogItem to a MailLogItem

        '
        (ideally, if you're going to do this, you'd probably want to use

        ' mLogItem as a global variable in the MailLogSubclass library, and

        '
        set it in the UseMailLog function)

        Dim mLogItem As New MailLogItem

        Set mLogItem = globalLogItem

        Call mLogItem.PrintToStatusBar("Hello")

        End Sub

        =============== CODE ENDS HERE ===============



        The comments in the code should be fairly self-explanatory.



        Please tell me if that doesn't help, or if the problem you're having is completely different, and I'll try to think of other things to look at.


      8. Julian
      • Got caught in another project

        By Thomas H Povlsen 2 decades ago

        Hi Julian,



        Thanks for your response.



        You might got it right wioth the second part of your answer.

        But i will sadly have to wait trying your suggestions.



        I will give you my result as soon as i have done some testing.



        Thanks so far.



        Merry christmas !



        /Thomas

      • Problem solved, thanks

        By Thomas H Povlsen 2 decades ago

        Hi Julian,



        The problem was the last one you described.



        Casting the LogItem-object into an object of my derived class solved the problem.



        Thanks alot for your help :-)



        Regards

        Thomas