Computer Science Canada

Class subprograms cannot be subprogram variables

Author:  ericfourfour [ Fri Sep 22, 2006 8:05 pm ]
Post subject:  Class subprograms cannot be subprogram variables

Today I was working on my gui, scrollbars to be precise, when I came across this error, "Class subprograms cannot be subprogram variables". Here is an example:
code:

class myclass
    export the_proc
    proc the_proc (hello : proc x ())
        hello ()
    end the_proc
end myclass

class myotherclass
    import myclass

    var my_class : ^myclass

    proc Init ()
        new myclass, my_class
    end Init

    proc hello ()
        put "Hello"
    end hello

    proc do_this ()
        my_class -> the_proc (hello)
    end do_this
end myotherclass

This is basically saying that I can't use procedures that are in a class as a parameter. Would there happen to be some way around this?

If your curious, I'm using my already made buttons in the scrollbar instead of coding more (the slider, and the arrow buttons). This means I only need to figure out where to place the slider and draw the background. Pretty simple I'd say. However, the buttons use action procedures, so that is where I'm having the problems.

If worse-comes-to-worse and there is no way around this problem, I will just end up deriving more button classes that handle actions in a different way than action procedures.

Author:  TheOneTrueGod [ Sun Sep 24, 2006 4:10 pm ]
Post subject: 

I think this is the same question I asked a couple months ago, and If I remember correctly, the answer is "too bad". Razz You'll have to find some other work-around.

Author:  Bored [ Sun Sep 24, 2006 9:52 pm ]
Post subject: 

Yes, as TOTG said, your pretty much out of luck here as there are things in most languages, escpecially Turing, that there is no easy way and have to be worked around. You'll experience many of these when working with the limited capabilities of Objects in Turing and be ready for most of your questions at this point in your Turing knowledge to be answered with a no clue, your out of luck, or a complicated work around that amounts to hours of work to implement and fix.

Author:  Tony [ Sun Sep 24, 2006 10:16 pm ]
Post subject: 

can you extend your generic_button into a scroll_bar ? Assuming that the error doesn't like passing functions around between different classes..

alternativly you could try keeping those argument functions outside of classes (common include file?) and try passing from there (or a reference to). I'm not sure how applicable this hack would be.


: